KiCad PCB EDA Suite
lib_view_frame.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) 2008 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 2004-2019 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 <class_libentry.h>
28 #include <class_library.h>
29 #include <confirm.h>
30 #include <dialog_helpers.h>
32 #include <eda_doc.h>
33 #include <eeschema_id.h>
34 #include <eeschema_settings.h>
35 #include <fctsys.h>
36 #include <kiface_i.h>
37 #include <kiway.h>
38 #include <lib_view_frame.h>
39 #include <msgpanel.h>
40 #include <sch_draw_panel.h>
41 #include <sch_view.h>
42 #include <sch_painter.h>
43 #include <symbol_lib_table.h>
45 #include <pgm_base.h>
47 #include <tool/tool_manager.h>
48 #include <tool/action_toolbar.h>
49 #include <tool/tool_dispatcher.h>
50 #include <tool/common_tools.h>
51 #include <tool/common_control.h>
52 #include <tool/zoom_tool.h>
53 #include <tools/ee_actions.h>
54 #include <tools/lib_control.h>
56 #include <view/view_controls.h>
57 
58 // Save previous component library viewer state.
61 
64 
65 
66 BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME )
67  // Window events
69  EVT_SIZE( LIB_VIEW_FRAME::OnSize )
70  EVT_ACTIVATE( LIB_VIEW_FRAME::OnActivate )
71 
72  // Toolbar events
77 
78  // listbox events
82 
83  // Menu (and/or hotkey) events
84  EVT_MENU( wxID_CLOSE, LIB_VIEW_FRAME::CloseLibraryViewer )
86 
88 
89 END_EVENT_TABLE()
90 
91 
92 #define LIB_VIEW_NAME "ViewlibFrame"
93 #define LIB_VIEW_NAME_MODAL "ViewlibFrameModal"
94 
95 #define LIB_VIEW_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
96 #define LIB_VIEW_STYLE_MODAL ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
97 
98 
99 LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
100  const wxString& aLibraryName ) :
101  SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Symbol Library Browser" ),
102  wxDefaultPosition, wxDefaultSize,
105  m_libList( nullptr ), m_cmpList( nullptr ), m_previewItem( nullptr )
106 {
107  wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL );
108 
109  if( aFrameType == FRAME_SCH_VIEWER_MODAL )
110  SetModal( true );
111 
112  m_AboutTitle = "Symbol Library Viewer";
113 
114  // Force the frame name used in config. the lib viewer frame has a name
115  // depending on aFrameType (needed to identify the frame by wxWidgets),
116  // but only one configuration is preferable.
118 
119  // Give an icon
120  wxIcon icon;
121  icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) );
122  SetIcon( icon );
123 
124  m_libListWidth = 200;
125  m_cmpListWidth = 300;
126  m_listPowerCmpOnly = false;
127 
128  // Initialize grid id to the default value (50 mils):
130 
131  SetScreen( new SCH_SCREEN( aKiway ) );
132  GetScreen()->m_Center = true; // Axis origin centered on screen.
133  LoadSettings( config() );
134 
135  // Synchronize some draw options
136  SetShowElectricalType( true );
137  // Ensure axis are always drawn (initial default display was not drawn)
139  gal_opts.m_axesEnabled = true;
140  GetCanvas()->GetGAL()->SetAxesEnabled( true );
143 
144  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
145 
146  setupTools();
147  ReCreateMenuBar();
150 
151  m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
152  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
153 
154  m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxDefaultPosition, wxDefaultSize,
155  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
156 
157  if( aLibraryName.empty() )
158  {
159  ReCreateListLib();
160  }
161  else
162  {
163  m_libraryName = aLibraryName;
164  m_entryName.Clear();
165  m_unit = 1;
166  m_convert = 1;
167  }
168 
169  m_selection_changed = false;
170 
171  DisplayLibInfos();
172 
173  m_auimgr.SetManagedWindow( this );
174 
175  // Manage main toolbar
176  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
177  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
178 
179  m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3)
180  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) );
181  m_auimgr.AddPane( m_cmpList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
182  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_cmpListWidth, -1 ) );
183 
184  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
185 
186  m_auimgr.GetPane( m_libList ).Show( aLibraryName.empty() );
187 
188  m_auimgr.Update();
189 
191 
192  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
193  {
194  Raise();
195  Show( true );
196  }
197 
198  SyncView();
199  GetCanvas()->GetViewControls()->SetSnapping( true );
200  GetCanvas()->SetCanFocus( false );
201 
202  // Set the working/draw area size to display a symbol to a reasonable value:
203  // A 450mm x 450mm with a origin at the area center looks like a large working area
204  double max_size_x = Millimeter2iu( 450 );
205  double max_size_y = Millimeter2iu( 450 );
206  BOX2D bbox;
207  bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
208  bbox.SetSize( max_size_x, max_size_y );
209  GetCanvas()->GetView()->SetBoundary( bbox );
211 }
212 
213 
215 {
216  // Shutdown all running tools
217  if( m_toolManager )
219 
220  if( m_previewItem )
222 }
223 
224 
226 {
227  // Create the manager and dispatcher & route draw panel events to the dispatcher
230  GetCanvas()->GetViewControls(), this );
231  m_actions = new EE_ACTIONS();
233 
234  // Register tools
238  m_toolManager->RegisterTool( new EE_INSPECTION_TOOL ); // manage show datasheet
239  m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); // manage context menu
241 
243 
244  // Run the selection tool, it is supposed to be always active
245  // It also manages the mouse right click to show the context menu
246  m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
247 
249 }
250 
251 
252 void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
253 {
254  m_unit = aUnit > 0 ? aUnit : 1;
255  m_convert = aConvert > 0 ? aConvert : LIB_ITEM::LIB_CONVERT::BASE;
256  m_selection_changed = false;
257 
259 }
260 
261 
263 {
264  LIB_PART* symbol = nullptr;
265 
266  if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
267  symbol = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
268 
269  return symbol;
270 }
271 
272 
274 {
275  LIB_PART* symbol = GetSelectedSymbol();
276  KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
277 
278  if( m_previewItem )
279  {
280  view->Remove( m_previewItem );
281  m_previewItem = nullptr;
282  }
283 
284  ClearMsgPanel();
285 
286  if( symbol )
287  {
290 
291  m_previewItem = symbol;
292  view->Add( m_previewItem );
293 
294  wxString parentName = _( "<none>" );
295  std::shared_ptr< LIB_PART > parent = m_previewItem->GetParent().lock();
296 
297  if( parent )
298  parentName = parent->GetName();
299 
300  AppendMsgPanel( _( "Name" ), m_previewItem->GetName(), BLUE, 6 );
301  AppendMsgPanel( _( "Parent" ), parentName, RED, 6 );
302  AppendMsgPanel( _( "Description" ), m_previewItem->GetDescription(), CYAN, 6 );
303  AppendMsgPanel( _( "Key words" ), m_previewItem->GetKeyWords(), DARKDARKGRAY );
304  }
305 
306  GetCanvas()->ForceRefresh();
307 }
308 
309 
310 bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
311 {
312  if( aSymbol && !aSymbol->IsEmpty() )
313  {
314  wxString msg;
315  LIB_TABLE* libTable = Prj().SchSymbolLibTable();
316  LIB_ID libid;
317 
318  libid.Parse( *aSymbol, LIB_ID::ID_SCH, true );
319 
320  if( libid.IsValid() )
321  {
322  wxString nickname = libid.GetLibNickname();
323 
324  if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
325  {
326  msg.sprintf( _( "The current configuration does not include a library with the\n"
327  "nickname \"%s\". Use Manage Symbol Libraries\n"
328  "to edit the configuration." ), nickname );
329  DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg );
330  }
331  else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
332  {
333  msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
334  "in the current configuration. Use Manage Symbol Libraries to\n"
335  "edit the configuration." ), nickname );
336  DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
337  }
338  else
339  {
342  }
343  }
344  }
345 
346  return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
347 }
348 
349 
350 void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
351 {
352  GetCanvas()->StopDrawing();
353 
354  if( !IsModal() )
355  {
356  Destroy();
357  }
358  else if( !IsDismissed() )
359  {
360  // only dismiss modal frame if not already dismissed.
361  DismissModal( false );
362 
363  // Modal frame will be destroyed by the calling function.
364  }
365 }
366 
367 
368 void LIB_VIEW_FRAME::OnSize( wxSizeEvent& SizeEv )
369 {
370  if( m_auimgr.GetManagedWindow() )
371  m_auimgr.Update();
372 
373  SizeEv.Skip();
374 }
375 
376 
377 void LIB_VIEW_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
378 {
379  LIB_PART* part = GetSelectedSymbol();
380 
381  int unit_count = 1;
382 
383  if( part )
384  unit_count = std::max( part->GetUnitCount(), 1 );
385 
386  m_unitChoice->Enable( unit_count > 1 );
387 
388  if( unit_count > 1 )
389  {
390  // rebuild the unit list if it is not suitable (after a new selection for instance)
391  if( unit_count != (int)m_unitChoice->GetCount() )
392  {
393  m_unitChoice->Clear();
394 
395  for( int ii = 0; ii < unit_count; ii++ )
396  m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
397 
398  }
399 
400  if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
401  m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
402  }
403  else if( m_unitChoice->GetCount() )
404  m_unitChoice->Clear();
405 }
406 
407 
409 {
410  if( !m_libList )
411  return false;
412 
413  m_libList->Clear();
414 
415  std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
416 
417  // Remove not allowed libs from main list, if the allowed lib list is not empty
418  if( m_allowedLibs.GetCount() )
419  {
420  for( unsigned ii = 0; ii < libs.size(); )
421  {
422  if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
423  libs.erase( libs.begin() + ii );
424  else
425  ii++;
426  }
427  }
428 
429  // Remove libs which have no power components, if this filter is activated
430  if( m_listPowerCmpOnly )
431  {
432  for( unsigned ii = 0; ii < libs.size(); )
433  {
434  wxArrayString aliasNames;
435 
436  Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
437 
438  if( aliasNames.IsEmpty() )
439  libs.erase( libs.begin() + ii );
440  else
441  ii++;
442  }
443  }
444 
445  if( libs.empty() )
446  return true;
447 
448  wxArrayString libNames;
449 
450  for( const auto& name : libs )
451  libNames.Add( name );
452 
453  m_libList->Append( libNames );
454 
455  // Search for a previous selection:
456  int index = m_libList->FindString( m_libraryName );
457 
458  if( index != wxNOT_FOUND )
459  {
460  m_libList->SetSelection( index, true );
461  }
462  else
463  {
464  // If not found, clear current library selection because it can be
465  // deleted after a config change.
466  m_libraryName = libs[0];
467  m_entryName = wxEmptyString;
468  m_unit = 1;
469  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
470  }
471 
472  bool cmp_changed = ReCreateListCmp();
473  DisplayLibInfos();
474  GetCanvas()->Refresh();
475 
476  return cmp_changed;
477 }
478 
479 
481 {
482  if( m_cmpList == NULL )
483  return false;
484 
485  wxArrayString aliasNames;
486 
487  try
488  {
489  Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
491  }
492  catch( const IO_ERROR& ) {} // ignore, it is handled below
493 
494  m_cmpList->Clear();
495 
496  if( aliasNames.IsEmpty() )
497  {
498  m_libraryName = wxEmptyString;
499  m_entryName = wxEmptyString;
500  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
501  m_unit = 1;
502  return true;
503  }
504 
505  m_cmpList->Append( aliasNames );
506 
507  int index = m_cmpList->FindString( m_entryName );
508  bool changed = false;
509 
510  if( index == wxNOT_FOUND )
511  {
512  // Select the first library entry when the previous entry name does not exist in
513  // the current library.
514  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
515  m_unit = 1;
516  index = 0;
517  changed = true;
518  m_entryName = wxEmptyString;
519  }
520 
521  m_cmpList->SetSelection( index, true );
522 
523  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
524  ProcessEvent( evt );
525 
526  return changed;
527 }
528 
529 
530 void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
531 {
532  int ii = m_libList->GetSelection();
533 
534  if( ii < 0 )
535  return;
536 
537  m_selection_changed = true;
538 
539  SetSelectedLibrary( m_libList->GetString( ii ) );
540 }
541 
542 
543 void LIB_VIEW_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
544 {
545  if( m_libraryName == aLibraryName )
546  return;
547 
548  m_libraryName = aLibraryName;
549  ReCreateListCmp();
550  GetCanvas()->Refresh();
551  DisplayLibInfos();
552 
553  // Ensure the corresponding line in m_libList is selected
554  // (which is not necessary the case if SetSelectedLibrary is called
555  // by another caller than ClickOnLibList.
556  m_libList->SetStringSelection( m_libraryName, true );
557  m_libList->SetFocus();
558 }
559 
560 
561 void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
562 {
563  int ii = m_cmpList->GetSelection();
564 
565  if( ii < 0 )
566  return;
567 
568  m_selection_changed = true;
569 
570  SetSelectedComponent( m_cmpList->GetString( ii ) );
571  m_cmpList->SetFocus();
572 }
573 
574 
575 void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName )
576 {
577  if( m_entryName != aComponentName )
578  {
579  m_entryName = aComponentName;
580 
581  // Ensure the corresponding line in m_cmpList is selected
582  // (which is not necessarily the case if SetSelectedComponent is called
583  // by another caller than ClickOnCmpList.
584  m_cmpList->SetStringSelection( aComponentName, true );
585  DisplayLibInfos();
586 
587  if( m_selection_changed )
588  {
589  m_unit = 1;
590  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
591  m_selection_changed = false;
592  }
593 
596  }
597 }
598 
599 
600 void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
601 {
603 }
604 
605 
607 {
608  auto cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
609 
611 
612  // Grid shape, etc.
613  GetGalDisplayOptions().ReadWindowSettings( cfg->m_LibViewPanel.window );
614 
615  m_libListWidth = cfg->m_LibViewPanel.lib_list_width;
616  m_cmpListWidth = cfg->m_LibViewPanel.cmp_list_width;
617  m_showPinElectricalTypeName = cfg->m_LibViewPanel.show_pin_electrical_type;
618 
619  // Set parameters to a reasonable value.
620  if( m_libListWidth > m_FrameSize.x/2 )
622 
623  if( m_cmpListWidth > m_FrameSize.x/2 )
625 }
626 
627 
629 {
630  auto cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
631 
633 
634  if( m_libListWidth && m_libList )
635  m_libListWidth = m_libList->GetSize().x;
636 
637  m_cmpListWidth = m_cmpList->GetSize().x;
638 
639  cfg->m_LibViewPanel.lib_list_width = m_libListWidth;
640  cfg->m_LibViewPanel.cmp_list_width = m_cmpListWidth;
641  cfg->m_LibViewPanel.show_pin_electrical_type = m_showPinElectricalTypeName;
642 }
643 
644 
646 {
647  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
648  wxASSERT( cfg );
649  return &cfg->m_LibViewPanel.window;
650 }
651 
652 
653 void LIB_VIEW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
654 {
655  SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
656 
657  if( aEnvVarsChanged )
658  ReCreateListLib();
659 }
660 
661 
662 void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
663 {
664  if( event.GetActive() )
665  {
666  bool changed = m_libList ? ReCreateListLib() : false;
667 
668  if (changed)
669  m_selection_changed = true;
670 
672 
673  DisplayLibInfos();
674  }
675 
676  event.Skip(); // required under wxMAC
677 }
678 
679 
680 void LIB_VIEW_FRAME::CloseLibraryViewer( wxCommandEvent& event )
681 {
682  Close();
683 }
684 
685 
687 {
688  m_listPowerCmpOnly = false;
689  m_allowedLibs.Clear();
690 
691  if( aFilter )
692  {
693  m_allowedLibs = aFilter->GetAllowedLibList();
695  }
696 
697  ReCreateListLib();
698 }
699 
700 
702 {
703  LIB_PART* part = GetSelectedSymbol();
704 
705  if( !part )
706  {
707  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
708  }
709  else
710  {
711  std::shared_ptr< LIB_PART > tmp;
712 
713  tmp = ( part->IsAlias() ) ? part->GetParent().lock() : part->SharedPtr();
714 
715  wxCHECK( tmp, BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ) );
716 
717  EDA_RECT bbox = tmp->GetUnitBoundingBox( m_unit, m_convert );
718  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
719  }
720 }
721 
722 
724 {
725  if( m_cmpList->GetSelection() >= 0 )
726  DismissModal( true, m_libraryName + ':' + m_cmpList->GetStringSelection() );
727  else
728  DismissModal( false );
729 
730  Close( true );
731 }
732 
733 
734 
735 void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
736 {
737  std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock );
738 
739  // One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway.
740  if( !dialogLock.try_lock() )
741  return;
742 
743  // Container doing search-as-you-type.
744  SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
745  auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs ) );
746  auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
747 
748  const auto libNicknames = libs->GetLogicalLibs();
749  adapter->AddLibraries( libNicknames, this );
750 
751  LIB_PART* current = GetSelectedSymbol();
752  LIB_ID id;
753  int unit = 0;
754 
755  if( current )
756  {
757  id = current->GetLibId();
758  adapter->SetPreselectNode( id, unit );
759  }
760 
761  wxString dialogTitle;
762  dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
763 
764  DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, m_convert, false, false, false );
765 
766  if( dlg.ShowQuasiModal() == wxID_CANCEL )
767  return;
768 
769  id = dlg.GetSelectedLibId( &unit );
770 
771  if( !id.IsValid() )
772  return;
773 
774  SetSelectedLibrary( id.GetLibNickname() );
775  SetSelectedComponent( id.GetLibItemName() );
776  SetUnitAndConvert( unit, 1 );
777 }
778 
779 
780 void LIB_VIEW_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
781 {
782  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
783  int ii = m_cmpList->GetSelection();
784 
785  // Select the next symbol or stop at the end of the list.
786  if( ii != wxNOT_FOUND || ii != (int)m_cmpList->GetCount() - 1 )
787  ii += 1;
788 
789  m_cmpList->SetSelection( ii );
790  ProcessEvent( evt );
791 }
792 
793 
794 void LIB_VIEW_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
795 {
796  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
797  int ii = m_cmpList->GetSelection();
798 
799  // Select the previous symbol or stop at the beginning of list.
800  if( ii != wxNOT_FOUND && ii != 0 )
801  ii -= 1;
802 
803  m_cmpList->SetSelection( ii );
804  ProcessEvent( evt );
805 }
806 
807 
808 void LIB_VIEW_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
809 {
810  int ii = m_unitChoice->GetSelection();
811 
812  if( ii < 0 )
813  return;
814 
815  m_unit = ii + 1;
816 
818 }
819 
820 
822 {
823  if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
824  {
825  const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName );
826 
827  wxString title = wxString::Format( _( "Symbol Library Browser -- %s" ),
828  row ? row->GetFullURI() : _( "no library selected" ) );
829  SetTitle( title );
830  }
831 }
832 
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
Definition: colors.h:57
static int m_unit
void SetScreen(BASE_SCREEN *aScreen) override
static int m_convert
KIGFX::SCH_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
void SetFilter(const SCHLIB_FILTER *aFilter)
Set a filter to display only libraries and/or components which match the filter.
LIB_PART * GetSelectedSymbol() const
static wxString m_entryName
BOX2< VECTOR2I > BOX2I
Definition: box2.h:521
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:103
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel.
LIB_ID GetLibId() const override
void SetUnitAndConvert(int aUnit, int aConvert)
Set unit and convert, and set flag preventing them from automatically resetting to 1.
bool m_selection_changed
Updated to true if a list rewrite on GUI activation resulted in the component selection changing,...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
bool ShowModal(wxString *aSymbol, wxWindow *aParent) override
Function ShowModal.
wxString GetName() const override
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
This file is part of the common library.
TOOL_DISPATCHER * m_toolDispatcher
bool IsDismissed()
Function IsDismissed returns false only if both the frame is acting in modal mode and it has not been...
VIEW_CONTROLS class definition.
This file is part of the common library.
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
void onSelectPreviousSymbol(wxCommandEvent &aEvent)
virtual bool IsGridVisible() const
void OnCloseWindow(wxCloseEvent &Event)
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:376
ACTIONS * m_actions
int GetWidth() const
Definition: eda_rect.h:119
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
wxString m_AboutTitle
wxListBox * m_cmpList
WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg) override
Returns a pointer to the window settings for this frame.
void SetSize(const Vec &size)
Definition: box2.h:211
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
wxArrayString m_allowedLibs
void SetShowElectricalType(bool aShow)
wxAuiManager m_auimgr
static wxString m_libraryName
ACTION_TOOLBAR * m_mainToolBar
wxString GetKeyWords() const
LIB_PART * m_previewItem
#define LIB_VIEW_NAME_MODAL
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
The base class for create windows for drawing purpose.
bool IsValid() const
Definition: lib_id.h:171
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID.
void SetSelectedComponent(const wxString &aComponentName)
Set the selected component.
Symbol library viewer main window.
static PTR Create(EDA_BASE_FRAME *aParent, LIB_TABLE *aLibs)
Factory function: create a model adapter in a reference-counting container.
bool m_axesEnabled
Whether or not to draw the coordinate system axes
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
LIB_CONTROL.
Definition: lib_control.h:39
Dialog class to select a component from the libraries.
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
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:52
void OnSelectSymbol(wxCommandEvent &aEvent)
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
#define LIB_VIEW_STYLE_MODAL
static TOOL_ACTION gridPreset
Definition: actions.h:134
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:75
#define NULL
int GetUnitCount() const override
For items with units, return the number of units.
LIB_VIEW_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aLibraryName=wxEmptyString)
Constructor.
void ReCreateMenuBar() override
Recreates the menu bar.
bool m_Center
Center on screen.
Definition: base_screen.h:121
void SyncView()
Mark all items for refresh.
EDA_MSG_PANEL * m_messagePanel
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
int ShowQuasiModal()
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
Class LIB_PIN definition.
void onUpdateUnitChoice(wxUpdateUIEvent &aEvent)
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void CloseLibraryViewer(wxCommandEvent &event)
PART_SPTR SharedPtr()
Definition: colors.h:59
PART_REF & GetParent()
Define a library symbol object.
Helper dialog and control classes.
void ReCreateHToolbar() override
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
Definition: colors.h:60
wxString GetDescription() override
static TOOL_ACTION addSymbolToSchematic
Definition: ee_actions.h:162
bool IsModal()
Definition: kiway_player.h:163
COMMON_CONTROL.
void SetAxesEnabled(bool aAxesEnabled)
Enables drawing the axes.
virtual void ClearMsgPanel()
Clear all messages from the message panel.
bool m_showPinElectricalTypeName
const BOX2I GetDocumentExtents() const override
bool ReCreateListCmp()
Create or recreate the list of components in the currently selected library.
bool GetFilterPowerParts() const
Specialization of the wxAuiPaneInfo class for KiCad panels.
int GetHeight() const
Definition: eda_rect.h:120
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
EESCHEMA_ACTIONS.
Definition: ee_actions.h:43
COMMON_TOOLS.
Definition: common_tools.h:38
TOOL_DISPATCHER.
void SetModal(bool aIsModal)
Definition: kiway_player.h:164
void ClickOnLibList(wxCommandEvent &event)
void onSelectNextSymbol(wxCommandEvent &aEvent)
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
void updatePreviewSymbol()
see class PGM_BASE
const char * name
Definition: DXF_plotter.cpp:60
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 DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets a dispatcher that processes events and forwards them to tools.
#define _(s)
Definition: 3d_actions.cpp:33
wxListBox * m_libList
void FinishModal()
Send the selected symbol back to the caller.
#define LIB_VIEW_STYLE
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnToggleShowLayerManager GERBVIEW_FRAME::OnSelectHighlightChoice EVT_UPDATE_UI(ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnUpdateLayerSelectBox) EVT_UPDATE_UI_RANGE(ID_TB_OPTIONS_SHOW_GBR_MODE_0
bool IsAlias() const
void SetOrigin(const Vec &pos)
Definition: box2.h:209
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void ClickOnCmpList(wxCommandEvent &event)
const wxArrayString & GetAllowedLibList() const
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).
void SetGridVisibility(bool aVisibility)
Sets the visibility setting of the grid.
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
void OnGridSettings(wxCommandEvent &aEvent) override
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
void OnActivate(wxActivateEvent &event)
Called when the frame is activated to reload the libraries and component lists that can be changed by...
wxChoice * m_unitChoice
const BITMAP_OPAQUE library_browse_xpm[1]
void ReCreateVToolbar() override
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
void onSelectSymbolUnit(wxCommandEvent &aEvent)
TOOL_MANAGER * m_toolManager
void InitTools()
Function InitTools() Initializes all registered tools.
Definition for part library class.
void SetBoundary(const BOX2D &aBoundary)
Function SetBoundary() Sets limits for view area.
Definition: view.h:267
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void DClickOnCmpList(wxCommandEvent &event)
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
virtual APP_SETTINGS_BASE * config()
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
Message panel definition file.
bool ReCreateListLib()
Creates or recreates a sorted list of currently loaded libraries.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
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
virtual bool ShowModal(wxString *aResult=NULL, wxWindow *aResultantFocusWindow=NULL)
Function ShowModal puts up this wxFrame as if it were a modal dialog, with all other instantiated wxF...
#define LIB_VIEW_NAME
bool ProcessEvent(wxEvent &aEvent) override
Override the default process event handler to implement the auto save feature.
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
void StopDrawing()
Function StopDrawing() Prevents the GAL canvas from further drawing till it is recreated or StartDraw...
wxString m_configName
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.
void SetSelectedLibrary(const wxString &aLibName)
Set the selected library in the library window.
bool GetShowElectricalType()
Allow some frames to show/hide pin electrical type names.
void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
void ReadWindowSettings(WINDOW_SETTINGS &aCfg)
Read GAL config options from applicaton-level config.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.