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 <fctsys.h>
35 #include <kiface_i.h>
36 #include <kiway.h>
37 #include <lib_view_frame.h>
38 #include <msgpanel.h>
39 #include <sch_draw_panel.h>
40 #include <sch_view.h>
41 #include <sch_painter.h>
42 #include <symbol_lib_table.h>
44 #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 // Save previous component library viewer state.
59 
62 
63 
64 BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME )
65  // Window events
67  EVT_SIZE( LIB_VIEW_FRAME::OnSize )
68  EVT_ACTIVATE( LIB_VIEW_FRAME::OnActivate )
69 
70  // Toolbar events
75 
76  // listbox events
80 
81  // Menu (and/or hotkey) events
82  EVT_MENU( wxID_CLOSE, LIB_VIEW_FRAME::CloseLibraryViewer )
84 
86 
87 END_EVENT_TABLE()
88 
89 
90 #define LIB_VIEW_NAME "ViewlibFrame"
91 #define LIB_VIEW_NAME_MODAL "ViewlibFrameModal"
92 
93 #define LIB_VIEW_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
94 #define LIB_VIEW_STYLE_MODAL ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
95 
96 
97 LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
98  const wxString& aLibraryName ) :
99  SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Symbol Library Browser" ),
100  wxDefaultPosition, wxDefaultSize,
103  m_libList( nullptr ), m_cmpList( nullptr ), m_previewItem( nullptr )
104 {
105  wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL );
106 
107  if( aFrameType == FRAME_SCH_VIEWER_MODAL )
108  SetModal( true );
109 
110  m_AboutTitle = "Symbol Library Viewer";
111 
112  // Force the frame name used in config. the lib viewer frame has a name
113  // depending on aFrameType (needed to identify the frame by wxWidgets),
114  // but only one configuration is preferable.
116 
117  // Give an icon
118  wxIcon icon;
119  icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) );
120  SetIcon( icon );
121 
122  m_libListWidth = 200;
123  m_cmpListWidth = 300;
124  m_listPowerCmpOnly = false;
125 
126  // Initialize grid id to the default value (50 mils):
128 
129  SetScreen( new SCH_SCREEN( aKiway ) );
130  GetScreen()->m_Center = true; // Axis origin centered on screen.
131  LoadSettings( config() );
132 
133  // Synchronize some draw options
134  SetShowElectricalType( true );
135  // Ensure axis are always drawn (initial default display was not drawn)
137  gal_opts.m_axesEnabled = true;
138  GetCanvas()->GetGAL()->SetAxesEnabled( true );
141 
142  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
143 
144  setupTools();
145  ReCreateMenuBar();
148 
149  m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
150  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
151 
152  m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxDefaultPosition, wxDefaultSize,
153  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
154 
155  if( aLibraryName.empty() )
156  {
157  ReCreateListLib();
158  }
159  else
160  {
161  m_libraryName = aLibraryName;
162  m_entryName.Clear();
163  m_unit = 1;
164  m_convert = 1;
165  }
166 
167  m_selection_changed = false;
168 
169  DisplayLibInfos();
170 
171  m_auimgr.SetManagedWindow( this );
172 
173  // Manage main toolbar
174  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
175  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
176 
177  m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3)
178  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) );
179  m_auimgr.AddPane( m_cmpList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
180  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_cmpListWidth, -1 ) );
181 
182  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
183 
184  m_auimgr.GetPane( m_libList ).Show( aLibraryName.empty() );
185 
186  m_auimgr.Update();
187 
189 
190  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
191  {
192  Raise();
193  Show( true );
194  }
195 
196  SyncView();
197  GetCanvas()->GetViewControls()->SetSnapping( true );
198  GetCanvas()->SetCanFocus( false );
199 
200  // Set the working/draw area size to display a symbol to a reasonable value:
201  // A 450mm x 450mm with a origin at the area center looks like a large working area
202  double max_size_x = Millimeter2iu( 450 );
203  double max_size_y = Millimeter2iu( 450 );
204  BOX2D bbox;
205  bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
206  bbox.SetSize( max_size_x, max_size_y );
207  GetCanvas()->GetView()->SetBoundary( bbox );
209 }
210 
211 
213 {
214  if( m_previewItem )
216 }
217 
218 
220 {
221  // Create the manager and dispatcher & route draw panel events to the dispatcher
224  GetCanvas()->GetViewControls(), this );
225  m_actions = new EE_ACTIONS();
227 
228  // Register tools
232  m_toolManager->RegisterTool( new EE_INSPECTION_TOOL ); // manage show datasheet
233  m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); // manage context menu
235 
237 
238  // Run the selection tool, it is supposed to be always active
239  // It also manages the mouse right click to show the context menu
240  m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
241 
243 }
244 
245 
246 void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
247 {
248  m_unit = aUnit > 0 ? aUnit : 1;
249  m_convert = aConvert > 0 ? aConvert : LIB_ITEM::LIB_CONVERT::BASE;
250  m_selection_changed = false;
251 
253 }
254 
255 
257 {
258  LIB_PART* symbol = nullptr;
259 
260  if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
261  symbol = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
262 
263  return symbol;
264 }
265 
266 
268 {
269  LIB_PART* symbol = GetSelectedSymbol();
270  KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
271 
272  if( m_previewItem )
273  {
274  view->Remove( m_previewItem );
275  m_previewItem = nullptr;
276  }
277 
278  ClearMsgPanel();
279 
280  if( symbol )
281  {
284 
285  m_previewItem = symbol;
286  view->Add( m_previewItem );
287 
288  wxString parentName = _( "<none>" );
289  std::shared_ptr< LIB_PART > parent = m_previewItem->GetParent().lock();
290 
291  if( parent )
292  parentName = parent->GetName();
293 
294  AppendMsgPanel( _( "Name" ), m_previewItem->GetName(), BLUE, 6 );
295  AppendMsgPanel( _( "Parent" ), parentName, RED, 6 );
296  AppendMsgPanel( _( "Description" ), m_previewItem->GetDescription(), CYAN, 6 );
297  AppendMsgPanel( _( "Key words" ), m_previewItem->GetKeyWords(), DARKDARKGRAY );
298  }
299 
300  GetCanvas()->ForceRefresh();
301 }
302 
303 
304 bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
305 {
306  if( aSymbol && !aSymbol->IsEmpty() )
307  {
308  wxString msg;
309  LIB_TABLE* libTable = Prj().SchSymbolLibTable();
310  LIB_ID libid;
311 
312  libid.Parse( *aSymbol, LIB_ID::ID_SCH, true );
313 
314  if( libid.IsValid() )
315  {
316  wxString nickname = libid.GetLibNickname();
317 
318  if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
319  {
320  msg.sprintf( _( "The current configuration does not include a library with the\n"
321  "nickname \"%s\". Use Manage Symbol Libraries\n"
322  "to edit the configuration." ), nickname );
323  DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg );
324  }
325  else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
326  {
327  msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
328  "in the current configuration. Use Manage Symbol Libraries to\n"
329  "edit the configuration." ), nickname );
330  DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
331  }
332  else
333  {
336  }
337  }
338  }
339 
340  return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
341 }
342 
343 
344 void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
345 {
346  GetCanvas()->StopDrawing();
347 
348  if( !IsModal() )
349  {
350  Destroy();
351  }
352  else if( !IsDismissed() )
353  {
354  // only dismiss modal frame if not already dismissed.
355  DismissModal( false );
356 
357  // Modal frame will be destroyed by the calling function.
358  }
359 }
360 
361 
362 void LIB_VIEW_FRAME::OnSize( wxSizeEvent& SizeEv )
363 {
364  if( m_auimgr.GetManagedWindow() )
365  m_auimgr.Update();
366 
367  SizeEv.Skip();
368 }
369 
370 
371 void LIB_VIEW_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
372 {
373  LIB_PART* part = GetSelectedSymbol();
374 
375  int unit_count = 1;
376 
377  if( part )
378  unit_count = std::max( part->GetUnitCount(), 1 );
379 
380  m_unitChoice->Enable( unit_count > 1 );
381 
382  if( unit_count > 1 )
383  {
384  // rebuild the unit list if it is not suitable (after a new selection for instance)
385  if( unit_count != (int)m_unitChoice->GetCount() )
386  {
387  m_unitChoice->Clear();
388 
389  for( int ii = 0; ii < unit_count; ii++ )
390  m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
391 
392  }
393 
394  if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
395  m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
396  }
397  else if( m_unitChoice->GetCount() )
398  m_unitChoice->Clear();
399 }
400 
401 
403 {
404  if( !m_libList )
405  return false;
406 
407  m_libList->Clear();
408 
409  std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
410 
411  // Remove not allowed libs from main list, if the allowed lib list is not empty
412  if( m_allowedLibs.GetCount() )
413  {
414  for( unsigned ii = 0; ii < libs.size(); )
415  {
416  if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
417  libs.erase( libs.begin() + ii );
418  else
419  ii++;
420  }
421  }
422 
423  // Remove libs which have no power components, if this filter is activated
424  if( m_listPowerCmpOnly )
425  {
426  for( unsigned ii = 0; ii < libs.size(); )
427  {
428  wxArrayString aliasNames;
429 
430  Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
431 
432  if( aliasNames.IsEmpty() )
433  libs.erase( libs.begin() + ii );
434  else
435  ii++;
436  }
437  }
438 
439  if( libs.empty() )
440  return true;
441 
442  wxArrayString libNames;
443 
444  for( const auto& name : libs )
445  libNames.Add( name );
446 
447  m_libList->Append( libNames );
448 
449  // Search for a previous selection:
450  int index = m_libList->FindString( m_libraryName );
451 
452  if( index != wxNOT_FOUND )
453  {
454  m_libList->SetSelection( index, true );
455  }
456  else
457  {
458  // If not found, clear current library selection because it can be
459  // deleted after a config change.
460  m_libraryName = libs[0];
461  m_entryName = wxEmptyString;
462  m_unit = 1;
463  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
464  }
465 
466  bool cmp_changed = ReCreateListCmp();
467  DisplayLibInfos();
468  GetCanvas()->Refresh();
469 
470  return cmp_changed;
471 }
472 
473 
475 {
476  if( m_cmpList == NULL )
477  return false;
478 
479  wxArrayString aliasNames;
480 
481  try
482  {
483  Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
485  }
486  catch( const IO_ERROR& ) {} // ignore, it is handled below
487 
488  m_cmpList->Clear();
489 
490  if( aliasNames.IsEmpty() )
491  {
492  m_libraryName = wxEmptyString;
493  m_entryName = wxEmptyString;
494  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
495  m_unit = 1;
496  return true;
497  }
498 
499  m_cmpList->Append( aliasNames );
500 
501  int index = m_cmpList->FindString( m_entryName );
502  bool changed = false;
503 
504  if( index == wxNOT_FOUND )
505  {
506  // Select the first library entry when the previous entry name does not exist in
507  // the current library.
508  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
509  m_unit = 1;
510  index = 0;
511  changed = true;
512  m_entryName = wxEmptyString;
513  }
514 
515  m_cmpList->SetSelection( index, true );
516 
517  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
518  ProcessEvent( evt );
519 
520  return changed;
521 }
522 
523 
524 void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
525 {
526  int ii = m_libList->GetSelection();
527 
528  if( ii < 0 )
529  return;
530 
531  m_selection_changed = true;
532 
533  SetSelectedLibrary( m_libList->GetString( ii ) );
534 }
535 
536 
537 void LIB_VIEW_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
538 {
539  if( m_libraryName == aLibraryName )
540  return;
541 
542  m_libraryName = aLibraryName;
543  ReCreateListCmp();
544  GetCanvas()->Refresh();
545  DisplayLibInfos();
546 
547  // Ensure the corresponding line in m_libList is selected
548  // (which is not necessary the case if SetSelectedLibrary is called
549  // by another caller than ClickOnLibList.
550  m_libList->SetStringSelection( m_libraryName, true );
551  m_libList->SetFocus();
552 }
553 
554 
555 void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
556 {
557  int ii = m_cmpList->GetSelection();
558 
559  if( ii < 0 )
560  return;
561 
562  m_selection_changed = true;
563 
564  SetSelectedComponent( m_cmpList->GetString( ii ) );
565  m_cmpList->SetFocus();
566 }
567 
568 
569 void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName )
570 {
571  if( m_entryName != aComponentName )
572  {
573  m_entryName = aComponentName;
574 
575  // Ensure the corresponding line in m_cmpList is selected
576  // (which is not necessarily the case if SetSelectedComponent is called
577  // by another caller than ClickOnCmpList.
578  m_cmpList->SetStringSelection( aComponentName, true );
579  DisplayLibInfos();
580 
581  if( m_selection_changed )
582  {
583  m_unit = 1;
584  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
585  m_selection_changed = false;
586  }
587 
590  }
591 }
592 
593 
594 void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
595 {
597 }
598 
599 
600 #define LIBLIST_WIDTH_KEY "ViewLiblistWidth"
601 #define CMPLIST_WIDTH_KEY "ViewCmplistWidth"
602 #define CMPVIEW_SHOW_PINELECTRICALTYPE_KEY "ViewCmpShowPinElectricalType"
603 
604 
605 void LIB_VIEW_FRAME::LoadSettings( wxConfigBase* aCfg )
606 {
608 
609  // Fetch display settings from Symbol Editor as the Symbol Viewer
610  // doesn't have its own config
611  wxString symbolEditor = LIB_EDIT_FRAME_NAME;
612  bool btmp;
613  COLOR4D wtmp;
614 
615  if( aCfg->Read( symbolEditor + ShowGridEntryKeyword, &btmp ) )
616  SetGridVisibility( btmp );
617 
618  if( wtmp.SetFromWxString( aCfg->Read( symbolEditor + GridColorEntryKeyword, wxT( "NONE" ) ) ) )
619  SetGridColor( wtmp );
620 
621  // Grid shape, etc.
622  GetGalDisplayOptions().ReadAppConfig( *aCfg, symbolEditor );
623 
624  aCfg->Read( LIBLIST_WIDTH_KEY, &m_libListWidth, 150 );
625  aCfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 150 );
627 
628  // Set parameters to a reasonable value.
629  if( m_libListWidth > m_FrameSize.x/2 )
631 
632  if( m_cmpListWidth > m_FrameSize.x/2 )
634 }
635 
636 
637 void LIB_VIEW_FRAME::SaveSettings( wxConfigBase* aCfg )
638 {
640 
641  if( m_libListWidth && m_libList )
642  {
643  m_libListWidth = m_libList->GetSize().x;
644  aCfg->Write( LIBLIST_WIDTH_KEY, m_libListWidth );
645  }
646 
647  m_cmpListWidth = m_cmpList->GetSize().x;
648  aCfg->Write( CMPLIST_WIDTH_KEY, m_cmpListWidth );
649 
651 }
652 
653 
654 void LIB_VIEW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
655 {
656  SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
657 
658  if( aEnvVarsChanged )
659  ReCreateListLib();
660 }
661 
662 
663 void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
664 {
665  if( event.GetActive() )
666  {
667  bool changed = m_libList ? ReCreateListLib() : false;
668 
669  if (changed)
670  m_selection_changed = true;
671 
673 
674  DisplayLibInfos();
675  }
676 
677  event.Skip(); // required under wxMAC
678 }
679 
680 
681 void LIB_VIEW_FRAME::CloseLibraryViewer( wxCommandEvent& event )
682 {
683  Close();
684 }
685 
686 
688 {
689  m_listPowerCmpOnly = false;
690  m_allowedLibs.Clear();
691 
692  if( aFilter )
693  {
694  m_allowedLibs = aFilter->GetAllowedLibList();
696  }
697 
698  ReCreateListLib();
699 }
700 
701 
703 {
704  LIB_PART* part = GetSelectedSymbol();
705 
706  if( !part )
707  {
708  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
709  }
710  else
711  {
712  std::shared_ptr< LIB_PART > tmp;
713 
714  tmp = ( part->IsAlias() ) ? part->GetParent().lock() : part->SharedPtr();
715 
716  wxCHECK( tmp, BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ) );
717 
718  EDA_RECT bbox = tmp->GetUnitBoundingBox( m_unit, m_convert );
719  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
720  }
721 }
722 
723 
725 {
726  if( m_cmpList->GetSelection() >= 0 )
727  DismissModal( true, m_libraryName + ':' + m_cmpList->GetStringSelection() );
728  else
729  DismissModal( false );
730 
731  Close( true );
732 }
733 
734 
735 
736 void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
737 {
738  std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock );
739 
740  // One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway.
741  if( !dialogLock.try_lock() )
742  return;
743 
744  // Container doing search-as-you-type.
745  SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
746  auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( libs ) );
747  auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
748 
749  const auto libNicknames = libs->GetLogicalLibs();
750  adapter->AddLibraries( libNicknames, this );
751 
752  LIB_PART* current = GetSelectedSymbol();
753  LIB_ID id;
754  int unit = 0;
755 
756  if( current )
757  {
758  id = current->GetLibId();
759  adapter->SetPreselectNode( id, unit );
760  }
761 
762  wxString dialogTitle;
763  dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
764 
765  DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, m_convert, false, false, false );
766 
767  if( dlg.ShowQuasiModal() == wxID_CANCEL )
768  return;
769 
770  id = dlg.GetSelectedLibId( &unit );
771 
772  if( !id.IsValid() )
773  return;
774 
775  SetSelectedLibrary( id.GetLibNickname() );
776  SetSelectedComponent( id.GetLibItemName() );
777  SetUnitAndConvert( unit, 1 );
778 }
779 
780 
781 void LIB_VIEW_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
782 {
783  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
784  int ii = m_cmpList->GetSelection();
785 
786  // Select the next symbol or stop at the end of the list.
787  if( ii != wxNOT_FOUND || ii != (int)m_cmpList->GetCount() - 1 )
788  ii += 1;
789 
790  m_cmpList->SetSelection( ii );
791  ProcessEvent( evt );
792 }
793 
794 
795 void LIB_VIEW_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
796 {
797  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
798  int ii = m_cmpList->GetSelection();
799 
800  // Select the previous symbol or stop at the beginning of list.
801  if( ii != wxNOT_FOUND && ii != 0 )
802  ii -= 1;
803 
804  m_cmpList->SetSelection( ii );
805  ProcessEvent( evt );
806 }
807 
808 
809 void LIB_VIEW_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
810 {
811  int ii = m_unitChoice->GetSelection();
812 
813  if( ii < 0 )
814  return;
815 
816  m_unit = ii + 1;
817 
819 }
820 
821 
823 {
824  if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
825  {
826  const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName );
827 
828  wxString title = wxString::Format( _( "Symbol Library Browser -- %s" ),
829  row ? row->GetFullURI() : _( "no library selected" ) );
830  SetTitle( title );
831  }
832 }
833 
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.
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:249
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:109
wxString m_AboutTitle
wxListBox * m_cmpList
virtual wxConfigBase * config()
Returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void SetSize(const Vec &size)
Definition: box2.h:211
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
wxArrayString m_allowedLibs
void SetShowElectricalType(bool aShow)
#define CMPVIEW_SHOW_PINELECTRICALTYPE_KEY
wxAuiManager m_auimgr
static wxString m_libraryName
ACTION_TOOLBAR * m_mainToolBar
wxString GetKeyWords() const
virtual void SetGridColor(COLOR4D aColor)
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
void SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data file.
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.
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
#define LIB_EDIT_FRAME_NAME
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:79
void OnSelectSymbol(wxCommandEvent &aEvent)
#define LIB_VIEW_STYLE_MODAL
static TOOL_ACTION gridPreset
Definition: actions.h:131
#define NULL
int GetUnitCount() const override
For items with units, return the number of units.
#define LIBLIST_WIDTH_KEY
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:274
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.
void ReadAppConfig(wxConfigBase &aCfg, const wxString &aBaseName)
Read GAL config options from applicaton-level config.
void LoadSettings(wxConfigBase *aCfg) override
Load common frame parameters from a configuration file.
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()
void SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data file.
static PTR Create(LIB_TABLE *aLibs)
Factory function: create a model adapter in a reference-counting container.
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:31
wxListBox * m_libList
void FinishModal()
Send the selected symbol back to the caller.
#define ShowGridEntryKeyword
Nonzero to show grid (suffix)
#define LIB_VIEW_STYLE
void LoadSettings(wxConfigBase *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
#define CMPLIST_WIDTH_KEY
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
virtual void SetGridVisibility(bool aVisible)
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 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
Message panel definition file.
bool ReCreateListLib()
Creates or recreates a sorted list of currently loaded libraries.
#define GridColorEntryKeyword
Grid color ID (suffix)
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.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.