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 <eeschema_id.h>
33 #include <eeschema_settings.h>
34 #include <fctsys.h>
35 #include <kiface_i.h>
36 #include <kiway.h>
37 #include <lib_view_frame.h>
38 #include <msgpanel.h>
39 #include <sch_view.h>
40 #include <sch_painter.h>
41 #include <symbol_lib_table.h>
43 #include <pgm_base.h>
45 #include <tool/tool_manager.h>
46 #include <tool/action_toolbar.h>
47 #include <tool/tool_dispatcher.h>
48 #include <tool/common_tools.h>
49 #include <tool/common_control.h>
50 #include <tool/zoom_tool.h>
51 #include <tools/ee_actions.h>
52 #include <tools/lib_control.h>
54 #include <view/view_controls.h>
55 
56 #include <default_values.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_unitChoice( nullptr ), m_libList( nullptr ),
106  m_cmpList( nullptr ), m_previewItem( nullptr )
107 {
108  wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL );
109 
110  if( aFrameType == FRAME_SCH_VIEWER_MODAL )
111  SetModal( true );
112 
113  m_AboutTitle = "Symbol Library Viewer";
114 
115  // Force the frame name used in config. the lib viewer frame has a name
116  // depending on aFrameType (needed to identify the frame by wxWidgets),
117  // but only one configuration is preferable.
119 
120  // Give an icon
121  wxIcon icon;
122  icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) );
123  SetIcon( icon );
124 
125  m_libListWidth = 200;
126  m_cmpListWidth = 300;
127  m_listPowerCmpOnly = false;
128 
129  SetScreen( new SCH_SCREEN );
130  GetScreen()->m_Center = true; // Axis origin centered on screen.
131  LoadSettings( config() );
132 
133  // Ensure axis are always drawn (initial default display was not drawn)
135  gal_opts.m_axesEnabled = true;
136  GetCanvas()->GetGAL()->SetAxesEnabled( true );
137 
141 
142  setupTools();
143 
146  ReCreateMenuBar(); // Create after toolbars so that SyncToolbars works
147 
148  m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
149  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
150 
151  m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxDefaultPosition, wxDefaultSize,
152  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
153 
154  if( aLibraryName.empty() )
155  {
156  ReCreateListLib();
157  }
158  else
159  {
160  m_libraryName = aLibraryName;
161  m_entryName.Clear();
162  m_unit = 1;
163  m_convert = 1;
164  }
165 
166  m_selection_changed = false;
167 
168  DisplayLibInfos();
169 
170  m_auimgr.SetManagedWindow( this );
171 
172  // Manage main toolbar
173  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
174  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
175 
176  m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3)
177  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) );
178  m_auimgr.AddPane( m_cmpList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
179  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_cmpListWidth, -1 ) );
180 
181  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
182 
183  m_auimgr.GetPane( m_libList ).Show( aLibraryName.empty() );
184 
185  m_auimgr.Update();
186 
187  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
188  {
189  Raise();
190  Show( true );
191  }
192 
193  SyncView();
194  GetCanvas()->GetViewControls()->SetSnapping( true );
195  GetCanvas()->SetCanFocus( false );
196 
197  // Set the working/draw area size to display a symbol to a reasonable value:
198  // A 450mm x 450mm with a origin at the area center looks like a large working area
199  double max_size_x = Millimeter2iu( 450 );
200  double max_size_y = Millimeter2iu( 450 );
201  BOX2D bbox;
202  bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
203  bbox.SetSize( max_size_x, max_size_y );
204  GetCanvas()->GetView()->SetBoundary( bbox );
206 }
207 
208 
210 {
211  // Shutdown all running tools
212  if( m_toolManager )
214 
215  if( m_previewItem )
217 }
218 
219 
221 {
222  // Create the manager and dispatcher & route draw panel events to the dispatcher
225  GetCanvas()->GetViewControls(), config(), this );
226  m_actions = new EE_ACTIONS();
228 
229  // Register tools
233  m_toolManager->RegisterTool( new EE_INSPECTION_TOOL ); // manage show datasheet
234  m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); // manage context menu
236 
238 
239  // Run the selection tool, it is supposed to be always active
240  // It also manages the mouse right click to show the context menu
241  m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
242 
244 }
245 
246 
247 void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
248 {
249  m_unit = aUnit > 0 ? aUnit : 1;
250  m_convert = aConvert > 0 ? aConvert : LIB_ITEM::LIB_CONVERT::BASE;
251  m_selection_changed = false;
252 
254 }
255 
256 
258 {
259  LIB_PART* symbol = nullptr;
260 
261  if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
262  symbol = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
263 
264  return symbol;
265 }
266 
267 
269 {
270  LIB_PART* symbol = GetSelectedSymbol();
271  KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
272 
273  if( m_previewItem )
274  {
275  view->Remove( m_previewItem );
276  m_previewItem = nullptr;
277  }
278 
279  ClearMsgPanel();
280 
281  if( symbol )
282  {
285 
286  m_previewItem = symbol;
287  view->Add( m_previewItem );
288 
289  wxString parentName = _( "<none>" );
290  std::shared_ptr< LIB_PART > parent = m_previewItem->GetParent().lock();
291 
292  if( parent )
293  parentName = parent->GetName();
294 
295  AppendMsgPanel( _( "Name" ), m_previewItem->GetName(), BLUE, 6 );
296  AppendMsgPanel( _( "Parent" ), parentName, RED, 6 );
297  AppendMsgPanel( _( "Description" ), m_previewItem->GetDescription(), CYAN, 6 );
298  AppendMsgPanel( _( "Key words" ), m_previewItem->GetKeyWords(), DARKDARKGRAY );
299  }
300 
301  GetCanvas()->ForceRefresh();
302 }
303 
304 
305 bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
306 {
307  if( aSymbol && !aSymbol->IsEmpty() )
308  {
309  wxString msg;
310  LIB_TABLE* libTable = Prj().SchSymbolLibTable();
311  LIB_ID libid;
312 
313  libid.Parse( *aSymbol, LIB_ID::ID_SCH, true );
314 
315  if( libid.IsValid() )
316  {
317  wxString nickname = libid.GetLibNickname();
318 
319  if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
320  {
321  msg.sprintf( _( "The current configuration does not include a library with the\n"
322  "nickname \"%s\". Use Manage Symbol Libraries\n"
323  "to edit the configuration." ), nickname );
324  DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg );
325  }
326  else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
327  {
328  msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
329  "in the current configuration. Use Manage Symbol Libraries to\n"
330  "edit the configuration." ), nickname );
331  DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
332  }
333  else
334  {
337  }
338  }
339  }
340 
341  return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
342 }
343 
344 
345 void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
346 {
347  GetCanvas()->StopDrawing();
348 
349  if( !IsModal() )
350  {
351  Destroy();
352  }
353  else if( !IsDismissed() )
354  {
355  // only dismiss modal frame if not already dismissed.
356  DismissModal( false );
357 
358  // Modal frame will be destroyed by the calling function.
359  }
360 }
361 
362 
363 void LIB_VIEW_FRAME::OnSize( wxSizeEvent& SizeEv )
364 {
365  if( m_auimgr.GetManagedWindow() )
366  m_auimgr.Update();
367 
368  SizeEv.Skip();
369 }
370 
371 
372 void LIB_VIEW_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
373 {
374  LIB_PART* part = GetSelectedSymbol();
375 
376  int unit_count = 1;
377 
378  if( part )
379  unit_count = std::max( part->GetUnitCount(), 1 );
380 
381  m_unitChoice->Enable( unit_count > 1 );
382 
383  if( unit_count > 1 )
384  {
385  // rebuild the unit list if it is not suitable (after a new selection for instance)
386  if( unit_count != (int)m_unitChoice->GetCount() )
387  {
388  m_unitChoice->Clear();
389 
390  for( int ii = 0; ii < unit_count; ii++ )
391  m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
392 
393  }
394 
395  if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
396  m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
397  }
398  else if( m_unitChoice->GetCount() )
399  m_unitChoice->Clear();
400 }
401 
402 
404 {
405  if( !m_libList )
406  return false;
407 
408  m_libList->Clear();
409 
410  std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
411 
412  // Remove not allowed libs from main list, if the allowed lib list is not empty
413  if( m_allowedLibs.GetCount() )
414  {
415  for( unsigned ii = 0; ii < libs.size(); )
416  {
417  if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
418  libs.erase( libs.begin() + ii );
419  else
420  ii++;
421  }
422  }
423 
424  // Remove libs which have no power components, if this filter is activated
425  if( m_listPowerCmpOnly )
426  {
427  for( unsigned ii = 0; ii < libs.size(); )
428  {
429  wxArrayString aliasNames;
430 
431  Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
432 
433  if( aliasNames.IsEmpty() )
434  libs.erase( libs.begin() + ii );
435  else
436  ii++;
437  }
438  }
439 
440  if( libs.empty() )
441  return true;
442 
443  wxArrayString libNames;
444 
445  for( const auto& name : libs )
446  libNames.Add( name );
447 
448  m_libList->Append( libNames );
449 
450  // Search for a previous selection:
451  int index = m_libList->FindString( m_libraryName );
452 
453  if( index != wxNOT_FOUND )
454  {
455  m_libList->SetSelection( index, true );
456  }
457  else
458  {
459  // If not found, clear current library selection because it can be
460  // deleted after a config change.
461  m_libraryName = libs[0];
462  m_entryName = wxEmptyString;
463  m_unit = 1;
464  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
465  }
466 
467  bool cmp_changed = ReCreateListCmp();
468  DisplayLibInfos();
469  GetCanvas()->Refresh();
470 
471  return cmp_changed;
472 }
473 
474 
476 {
477  if( m_cmpList == NULL )
478  return false;
479 
480  wxArrayString aliasNames;
481 
482  try
483  {
484  Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
486  }
487  catch( const IO_ERROR& ) {} // ignore, it is handled below
488 
489  m_cmpList->Clear();
490 
491  if( aliasNames.IsEmpty() )
492  {
493  m_libraryName = wxEmptyString;
494  m_entryName = wxEmptyString;
495  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
496  m_unit = 1;
497  return true;
498  }
499 
500  m_cmpList->Append( aliasNames );
501 
502  int index = m_cmpList->FindString( m_entryName );
503  bool changed = false;
504 
505  if( index == wxNOT_FOUND )
506  {
507  // Select the first library entry when the previous entry name does not exist in
508  // the current library.
509  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
510  m_unit = 1;
511  index = 0;
512  changed = true;
513  m_entryName = wxEmptyString;
514  }
515 
516  m_cmpList->SetSelection( index, true );
517 
518  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
519  ProcessEvent( evt );
520 
521  return changed;
522 }
523 
524 
525 void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
526 {
527  int ii = m_libList->GetSelection();
528 
529  if( ii < 0 )
530  return;
531 
532  m_selection_changed = true;
533 
534  SetSelectedLibrary( m_libList->GetString( ii ) );
535 }
536 
537 
538 void LIB_VIEW_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
539 {
540  if( m_libraryName == aLibraryName )
541  return;
542 
543  m_libraryName = aLibraryName;
544  ReCreateListCmp();
545  GetCanvas()->Refresh();
546  DisplayLibInfos();
547 
548  // Ensure the corresponding line in m_libList is selected
549  // (which is not necessary the case if SetSelectedLibrary is called
550  // by another caller than ClickOnLibList.
551  m_libList->SetStringSelection( m_libraryName, true );
552 
553  // The m_libList has now the focus, in order to be able to use arrow keys
554  // to navigate inside the list.
555  // the gal canvas must not steal the focus to allow navigation
556  GetCanvas()->SetStealsFocus( false );
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 
572  // The m_cmpList has now the focus, in order to be able to use arrow keys
573  // to navigate inside the list.
574  // the gal canvas must not steal the focus to allow navigation
575  GetCanvas()->SetStealsFocus( false );
576  m_cmpList->SetFocus();
577 }
578 
579 
580 void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName )
581 {
582  if( m_entryName != aComponentName )
583  {
584  m_entryName = aComponentName;
585 
586  // Ensure the corresponding line in m_cmpList is selected
587  // (which is not necessarily the case if SetSelectedComponent is called
588  // by another caller than ClickOnCmpList.
589  m_cmpList->SetStringSelection( aComponentName, true );
590  DisplayLibInfos();
591 
592  if( m_selection_changed )
593  {
594  m_unit = 1;
595  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
596  m_selection_changed = false;
597  }
598 
601  }
602 }
603 
604 
605 void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
606 {
608 }
609 
610 
612 {
613  auto cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
614 
616 
617  // Grid shape, etc.
618  GetGalDisplayOptions().ReadWindowSettings( cfg->m_LibViewPanel.window );
619 
620  m_libListWidth = cfg->m_LibViewPanel.lib_list_width;
621  m_cmpListWidth = cfg->m_LibViewPanel.cmp_list_width;
622 
623  GetRenderSettings()->m_ShowPinsElectricalType = cfg->m_LibViewPanel.show_pin_electrical_type;
624 
625  // Set parameters to a reasonable value.
626  if( m_libListWidth > m_FrameSize.x/2 )
628 
629  if( m_cmpListWidth > m_FrameSize.x/2 )
631 }
632 
633 
635 {
636  EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
637 
639 
640  if( m_libListWidth && m_libList )
641  m_libListWidth = m_libList->GetSize().x;
642 
643  m_cmpListWidth = m_cmpList->GetSize().x;
644 
648 }
649 
650 
652 {
653  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
654  wxASSERT( cfg );
655  return &cfg->m_LibViewPanel.window;
656 }
657 
658 
659 void LIB_VIEW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
660 {
661  SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
662 
663  if( aEnvVarsChanged )
664  ReCreateListLib();
665 }
666 
667 
668 void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
669 {
670  if( event.GetActive() )
671  {
672  bool changed = m_libList ? ReCreateListLib() : false;
673 
674  if (changed)
675  m_selection_changed = true;
676 
678 
679  DisplayLibInfos();
680  }
681 
682  event.Skip(); // required under wxMAC
683 }
684 
685 
686 void LIB_VIEW_FRAME::CloseLibraryViewer( wxCommandEvent& event )
687 {
688  Close();
689 }
690 
691 
693 {
694  m_listPowerCmpOnly = false;
695  m_allowedLibs.Clear();
696 
697  if( aFilter )
698  {
699  m_allowedLibs = aFilter->GetAllowedLibList();
701  }
702 
703  ReCreateListLib();
704 }
705 
706 
708 {
709  LIB_PART* part = GetSelectedSymbol();
710 
711  if( !part )
712  {
713  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
714  }
715  else
716  {
717  std::shared_ptr< LIB_PART > tmp;
718 
719  tmp = ( part->IsAlias() ) ? part->GetParent().lock() : part->SharedPtr();
720 
721  wxCHECK( tmp, BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ) );
722 
723  EDA_RECT bbox = tmp->GetUnitBoundingBox( m_unit, m_convert );
724  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
725  }
726 }
727 
728 
730 {
731  if( m_cmpList->GetSelection() >= 0 )
732  DismissModal( true, m_libraryName + ':' + m_cmpList->GetStringSelection() );
733  else
734  DismissModal( false );
735 
736  Close( true );
737 }
738 
739 
740 
741 void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
742 {
743  std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock );
744 
745  // One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway.
746  if( !dialogLock.try_lock() )
747  return;
748 
749  // Container doing search-as-you-type.
750  SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
751  auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs ) );
752  auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
753 
754  const auto libNicknames = libs->GetLogicalLibs();
755  adapter->AddLibraries( libNicknames, this );
756 
757  LIB_PART* current = GetSelectedSymbol();
758  LIB_ID id;
759  int unit = 0;
760 
761  if( current )
762  {
763  id = current->GetLibId();
764  adapter->SetPreselectNode( id, unit );
765  }
766 
767  wxString dialogTitle;
768  dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
769 
770  DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, m_convert, false, false, false );
771 
772  if( dlg.ShowQuasiModal() == wxID_CANCEL )
773  return;
774 
775  id = dlg.GetSelectedLibId( &unit );
776 
777  if( !id.IsValid() )
778  return;
779 
780  SetSelectedLibrary( id.GetLibNickname() );
781  SetSelectedComponent( id.GetLibItemName() );
782  SetUnitAndConvert( unit, 1 );
783 }
784 
785 
786 void LIB_VIEW_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
787 {
788  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
789  int ii = m_cmpList->GetSelection();
790 
791  // Select the next symbol or stop at the end of the list.
792  if( ii != wxNOT_FOUND || ii != (int)m_cmpList->GetCount() - 1 )
793  ii += 1;
794 
795  m_cmpList->SetSelection( ii );
796  ProcessEvent( evt );
797 }
798 
799 
800 void LIB_VIEW_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
801 {
802  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
803  int ii = m_cmpList->GetSelection();
804 
805  // Select the previous symbol or stop at the beginning of list.
806  if( ii != wxNOT_FOUND && ii != 0 )
807  ii -= 1;
808 
809  m_cmpList->SetSelection( ii );
810  ProcessEvent( evt );
811 }
812 
813 
814 void LIB_VIEW_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
815 {
816  int ii = m_unitChoice->GetSelection();
817 
818  if( ii < 0 )
819  return;
820 
821  m_unit = ii + 1;
822 
824 }
825 
826 
828 {
829  if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
830  {
831  const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName );
832 
833  wxString title = wxString::Format( _( "Symbol Library Browser -- %s" ),
834  row ? row->GetFullURI() : _( "no library selected" ) );
835  SetTitle( title );
836  }
837 }
838 
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
static int m_unit
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...
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:104
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.
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
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.
bool IsDismissed()
Function IsDismissed returns false only if both the frame is acting in modal mode and it has not been...
virtual void SetScreen(BASE_SCREEN *aScreen)
VIEW_CONTROLS class definition.
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)
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
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:140
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
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
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
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:51
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:68
void OnSelectSymbol(wxCommandEvent &aEvent)
#define LIB_VIEW_STYLE_MODAL
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:91
#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:71
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()
PART_REF & GetParent()
void SetStealsFocus(bool aStealsFocus)
Set whether focus is taken on certain events (mouseover, keys, etc).
ACTIONS * m_actions
Definition: tools_holder.h:49
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.
Definition: color4d.h:58
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
wxString GetDescription() override
static TOOL_ACTION addSymbolToSchematic
Definition: ee_actions.h:162
COMMON_CONTROL.
void SetAxesEnabled(bool aAxesEnabled)
Enables drawing the axes.
virtual void ClearMsgPanel()
Clear all messages from the message panel.
const BOX2I GetDocumentExtents() const override
bool ReCreateListCmp()
Create or recreate the list of components in the currently selected library.
Definition: color4d.h:59
bool GetFilterPowerParts() const
Specialization of the wxAuiPaneInfo class for KiCad panels.
#define DEFAULT_LINE_THICKNESS
The default wire width in mils. (can be changed in preference menu)
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...
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:50
EESCHEMA_ACTIONS.
Definition: ee_actions.h:41
COMMON_TOOLS.
Definition: common_tools.h:38
TOOL_DISPATCHER.
void SetModal(bool aIsModal)
Definition: kiway_player.h:177
PANEL_LIB_VIEW m_LibViewPanel
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()
Definition: color4d.h:56
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
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 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).
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.
bool IsModal() const
Definition: kiway_player.h:176
#define LIB_VIEW_STYLE
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
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 CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
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)
#define IU_PER_MILS
Definition: plotter.cpp:138
const wxArrayString & GetAllowedLibList() const
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
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
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:74
void OnGridSettings(wxCommandEvent &event)
void onSelectSymbolUnit(wxCommandEvent &aEvent)
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 DClickOnCmpList(wxCommandEvent &event)
void SetDefaultPenWidth(int aWidth)
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
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.
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.