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/action_toolbar.h>
46 #include <tool/common_control.h>
47 #include <tool/common_tools.h>
48 #include <tool/editor_conditions.h>
49 #include <tool/selection.h>
50 #include <tool/tool_dispatcher.h>
51 #include <tool/tool_manager.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 #include <default_values.h>
59 
60 // Save previous component library viewer state.
63 
66 
67 
68 BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME )
69  // Window events
71  EVT_SIZE( LIB_VIEW_FRAME::OnSize )
72  EVT_ACTIVATE( LIB_VIEW_FRAME::OnActivate )
73 
74  // Toolbar events
79 
80  // listbox events
84 
85  // Menu (and/or hotkey) events
86  EVT_MENU( wxID_CLOSE, LIB_VIEW_FRAME::CloseLibraryViewer )
88 
90 
91 END_EVENT_TABLE()
92 
93 
94 #define LIB_VIEW_NAME "ViewlibFrame"
95 #define LIB_VIEW_NAME_MODAL "ViewlibFrameModal"
96 
97 #define LIB_VIEW_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
98 #define LIB_VIEW_STYLE_MODAL ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
99 
100 
101 LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
102  const wxString& aLibraryName ) :
103  SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Symbol Library Browser" ),
104  wxDefaultPosition, wxDefaultSize,
107  m_unitChoice( nullptr ), m_libList( nullptr ),
108  m_cmpList( nullptr ), m_previewItem( nullptr )
109 {
110  wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL );
111 
112  if( aFrameType == FRAME_SCH_VIEWER_MODAL )
113  SetModal( true );
114 
115  m_AboutTitle = "Symbol Library Viewer";
116 
117  // Force the frame name used in config. the lib viewer frame has a name
118  // depending on aFrameType (needed to identify the frame by wxWidgets),
119  // but only one configuration is preferable.
121 
122  // Give an icon
123  wxIcon icon;
124  icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) );
125  SetIcon( icon );
126 
127  m_libListWidth = 200;
128  m_cmpListWidth = 300;
129  m_listPowerCmpOnly = false;
130 
131  SetScreen( new SCH_SCREEN );
132  GetScreen()->m_Center = true; // Axis origin centered on screen.
133  LoadSettings( config() );
134 
135  // Ensure axis are always drawn (initial default display was not drawn)
137  gal_opts.m_axesEnabled = true;
138  GetCanvas()->GetGAL()->SetAxesEnabled( true );
139 
143 
144  setupTools();
146 
149  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 
190  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
191  {
192  Raise();
193  Show( true );
194  }
195 
196  SyncView();
197  GetCanvas()->SetCanFocus( false );
198 
199  // Set the working/draw area size to display a symbol to a reasonable value:
200  // A 450mm x 450mm with a origin at the area center looks like a large working area
201  double max_size_x = Millimeter2iu( 450 );
202  double max_size_y = Millimeter2iu( 450 );
203  BOX2D bbox;
204  bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
205  bbox.SetSize( max_size_x, max_size_y );
206  GetCanvas()->GetView()->SetBoundary( bbox );
208 }
209 
210 
212 {
213  // Shutdown all running tools
214  if( m_toolManager )
216 
217  if( m_previewItem )
219 }
220 
221 
223 {
224  // Create the manager and dispatcher & route draw panel events to the dispatcher
227  GetCanvas()->GetViewControls(), config(), this );
228  m_actions = new EE_ACTIONS();
230 
231  // Register tools
235  m_toolManager->RegisterTool( new EE_INSPECTION_TOOL ); // manage show datasheet
236  m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); // manage context menu
238 
240 
241  // Run the selection tool, it is supposed to be always active
242  // It also manages the mouse right click to show the context menu
243  m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
244 
246 }
247 
248 
250 {
252 
254  EDITOR_CONDITIONS cond( this );
255 
256  wxASSERT( mgr );
257 
258 #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
259 #define CHECK( x ) ACTION_CONDITIONS().Check( x )
260 
262 
263  auto electricalTypesShownCondition =
264  [this] ( const SELECTION& aSel )
265  {
267  };
268 
269  auto demorganCond =
270  [this] ( const SELECTION& )
271  {
272  LIB_PART* symbol = GetSelectedSymbol();
273 
274  return symbol && symbol->HasConversion();
275  };
276 
277  auto demorganStandardCond =
278  [] ( const SELECTION& )
279  {
280  return m_convert == LIB_ITEM::LIB_CONVERT::BASE;
281  };
282 
283  auto demorganAlternateCond =
284  [] ( const SELECTION& )
285  {
286  return m_convert == LIB_ITEM::LIB_CONVERT::DEMORGAN;
287  };
288 
289  auto haveDatasheetCond =
290  [this] ( const SELECTION& )
291  {
292  LIB_PART* symbol = GetSelectedSymbol();
293 
294  return symbol && !symbol->GetDatasheetField().GetText().IsEmpty();
295  };
296 
297  mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
298  mgr->SetConditions( EE_ACTIONS::showElectricalTypes, CHECK( electricalTypesShownCondition ) );
299 
301  ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganStandardCond ) );
303  ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganAlternateCond ) );
304 
305 #undef CHECK
306 #undef ENABLE
307 }
308 
309 
310 void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
311 {
312  m_unit = aUnit > 0 ? aUnit : 1;
313  m_convert = aConvert > 0 ? aConvert : LIB_ITEM::LIB_CONVERT::BASE;
314  m_selection_changed = false;
315 
317 }
318 
319 
321 {
322  LIB_PART* symbol = nullptr;
323 
324  if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
325  symbol = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
326 
327  return symbol;
328 }
329 
330 
332 {
333  LIB_PART* symbol = GetSelectedSymbol();
334  KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
335 
336  if( m_previewItem )
337  {
338  view->Remove( m_previewItem );
339  m_previewItem = nullptr;
340  }
341 
342  ClearMsgPanel();
343 
344  if( symbol )
345  {
348 
349  m_previewItem = symbol;
350  view->Add( m_previewItem );
351 
352  wxString parentName = _( "<none>" );
353  std::shared_ptr< LIB_PART > parent = m_previewItem->GetParent().lock();
354 
355  if( parent )
356  parentName = parent->GetName();
357 
358  AppendMsgPanel( _( "Name" ), m_previewItem->GetName(), BLUE, 6 );
359  AppendMsgPanel( _( "Parent" ), parentName, RED, 6 );
360  AppendMsgPanel( _( "Description" ), m_previewItem->GetDescription(), CYAN, 6 );
361  AppendMsgPanel( _( "Key words" ), m_previewItem->GetKeyWords(), DARKDARKGRAY );
362  }
363 
364  GetCanvas()->ForceRefresh();
365 }
366 
367 
368 bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
369 {
370  if( aSymbol && !aSymbol->IsEmpty() )
371  {
372  wxString msg;
373  LIB_TABLE* libTable = Prj().SchSymbolLibTable();
374  LIB_ID libid;
375 
376  libid.Parse( *aSymbol, LIB_ID::ID_SCH, true );
377 
378  if( libid.IsValid() )
379  {
380  wxString nickname = libid.GetLibNickname();
381 
382  if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
383  {
384  msg.sprintf( _( "The current configuration does not include a library with the\n"
385  "nickname \"%s\". Use Manage Symbol Libraries\n"
386  "to edit the configuration." ), nickname );
387  DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg );
388  }
389  else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
390  {
391  msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
392  "in the current configuration. Use Manage Symbol Libraries to\n"
393  "edit the configuration." ), nickname );
394  DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
395  }
396  else
397  {
400  }
401  }
402  }
403 
404  return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
405 }
406 
407 
408 void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
409 {
410  GetCanvas()->StopDrawing();
411 
412  if( !IsModal() )
413  {
414  Destroy();
415  }
416  else if( !IsDismissed() )
417  {
418  // only dismiss modal frame if not already dismissed.
419  DismissModal( false );
420 
421  // Modal frame will be destroyed by the calling function.
422  }
423 }
424 
425 
426 void LIB_VIEW_FRAME::OnSize( wxSizeEvent& SizeEv )
427 {
428  if( m_auimgr.GetManagedWindow() )
429  m_auimgr.Update();
430 
431  SizeEv.Skip();
432 }
433 
434 
435 void LIB_VIEW_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
436 {
437  LIB_PART* part = GetSelectedSymbol();
438 
439  int unit_count = 1;
440 
441  if( part )
442  unit_count = std::max( part->GetUnitCount(), 1 );
443 
444  m_unitChoice->Enable( unit_count > 1 );
445 
446  if( unit_count > 1 )
447  {
448  // rebuild the unit list if it is not suitable (after a new selection for instance)
449  if( unit_count != (int)m_unitChoice->GetCount() )
450  {
451  m_unitChoice->Clear();
452 
453  for( int ii = 0; ii < unit_count; ii++ )
454  m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
455 
456  }
457 
458  if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
459  m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
460  }
461  else if( m_unitChoice->GetCount() )
462  m_unitChoice->Clear();
463 }
464 
465 
467 {
468  if( !m_libList )
469  return false;
470 
471  m_libList->Clear();
472 
473  std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
474 
475  // Remove not allowed libs from main list, if the allowed lib list is not empty
476  if( m_allowedLibs.GetCount() )
477  {
478  for( unsigned ii = 0; ii < libs.size(); )
479  {
480  if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
481  libs.erase( libs.begin() + ii );
482  else
483  ii++;
484  }
485  }
486 
487  // Remove libs which have no power components, if this filter is activated
488  if( m_listPowerCmpOnly )
489  {
490  for( unsigned ii = 0; ii < libs.size(); )
491  {
492  wxArrayString aliasNames;
493 
494  Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
495 
496  if( aliasNames.IsEmpty() )
497  libs.erase( libs.begin() + ii );
498  else
499  ii++;
500  }
501  }
502 
503  if( libs.empty() )
504  return true;
505 
506  wxArrayString libNames;
507 
508  for( const auto& name : libs )
509  libNames.Add( name );
510 
511  m_libList->Append( libNames );
512 
513  // Search for a previous selection:
514  int index = m_libList->FindString( m_libraryName );
515 
516  if( index != wxNOT_FOUND )
517  {
518  m_libList->SetSelection( index, true );
519  }
520  else
521  {
522  // If not found, clear current library selection because it can be
523  // deleted after a config change.
524  m_libraryName = libs[0];
525  m_entryName = wxEmptyString;
526  m_unit = 1;
527  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
528  }
529 
530  bool cmp_changed = ReCreateListCmp();
531  DisplayLibInfos();
532  GetCanvas()->Refresh();
533 
534  return cmp_changed;
535 }
536 
537 
539 {
540  if( m_cmpList == NULL )
541  return false;
542 
543  wxArrayString aliasNames;
544 
545  try
546  {
547  Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
549  }
550  catch( const IO_ERROR& ) {} // ignore, it is handled below
551 
552  m_cmpList->Clear();
553 
554  if( aliasNames.IsEmpty() )
555  {
556  m_libraryName = wxEmptyString;
557  m_entryName = wxEmptyString;
558  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
559  m_unit = 1;
560  return true;
561  }
562 
563  m_cmpList->Append( aliasNames );
564 
565  int index = m_cmpList->FindString( m_entryName );
566  bool changed = false;
567 
568  if( index == wxNOT_FOUND )
569  {
570  // Select the first library entry when the previous entry name does not exist in
571  // the current library.
572  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
573  m_unit = 1;
574  index = 0;
575  changed = true;
576  m_entryName = wxEmptyString;
577  }
578 
579  m_cmpList->SetSelection( index, true );
580 
581  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
582  ProcessEvent( evt );
583 
584  return changed;
585 }
586 
587 
588 void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
589 {
590  int ii = m_libList->GetSelection();
591 
592  if( ii < 0 )
593  return;
594 
595  m_selection_changed = true;
596 
597  SetSelectedLibrary( m_libList->GetString( ii ) );
598 }
599 
600 
601 void LIB_VIEW_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
602 {
603  if( m_libraryName == aLibraryName )
604  return;
605 
606  m_libraryName = aLibraryName;
607  ReCreateListCmp();
608  GetCanvas()->Refresh();
609  DisplayLibInfos();
610 
611  // Ensure the corresponding line in m_libList is selected
612  // (which is not necessary the case if SetSelectedLibrary is called
613  // by another caller than ClickOnLibList.
614  m_libList->SetStringSelection( m_libraryName, true );
615 
616  // The m_libList has now the focus, in order to be able to use arrow keys
617  // to navigate inside the list.
618  // the gal canvas must not steal the focus to allow navigation
619  GetCanvas()->SetStealsFocus( false );
620  m_libList->SetFocus();
621 }
622 
623 
624 void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
625 {
626  int ii = m_cmpList->GetSelection();
627 
628  if( ii < 0 )
629  return;
630 
631  m_selection_changed = true;
632 
633  SetSelectedComponent( m_cmpList->GetString( ii ) );
634 
635  // The m_cmpList has now the focus, in order to be able to use arrow keys
636  // to navigate inside the list.
637  // the gal canvas must not steal the focus to allow navigation
638  GetCanvas()->SetStealsFocus( false );
639  m_cmpList->SetFocus();
640 }
641 
642 
643 void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName )
644 {
645  if( m_entryName != aComponentName )
646  {
647  m_entryName = aComponentName;
648 
649  // Ensure the corresponding line in m_cmpList is selected
650  // (which is not necessarily the case if SetSelectedComponent is called
651  // by another caller than ClickOnCmpList.
652  m_cmpList->SetStringSelection( aComponentName, true );
653  DisplayLibInfos();
654 
655  if( m_selection_changed )
656  {
657  m_unit = 1;
658  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
659  m_selection_changed = false;
660  }
661 
664  }
665 }
666 
667 
668 void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
669 {
671 }
672 
673 
675 {
676  auto cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
677 
679 
680  // Grid shape, etc.
681  GetGalDisplayOptions().ReadWindowSettings( cfg->m_LibViewPanel.window );
682 
683  m_libListWidth = cfg->m_LibViewPanel.lib_list_width;
684  m_cmpListWidth = cfg->m_LibViewPanel.cmp_list_width;
685 
686  GetRenderSettings()->m_ShowPinsElectricalType = cfg->m_LibViewPanel.show_pin_electrical_type;
687 
688  // Set parameters to a reasonable value.
689  if( m_libListWidth > m_FrameSize.x/2 )
691 
692  if( m_cmpListWidth > m_FrameSize.x/2 )
694 }
695 
696 
698 {
699  EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
700 
702 
703  if( m_libListWidth && m_libList )
704  m_libListWidth = m_libList->GetSize().x;
705 
706  m_cmpListWidth = m_cmpList->GetSize().x;
707 
711 }
712 
713 
715 {
716  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
717  wxASSERT( cfg );
718  return &cfg->m_LibViewPanel.window;
719 }
720 
721 
722 void LIB_VIEW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
723 {
724  SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
725 
726  if( aEnvVarsChanged )
727  ReCreateListLib();
728 }
729 
730 
731 void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
732 {
733  if( event.GetActive() )
734  {
735  bool changed = m_libList ? ReCreateListLib() : false;
736 
737  if (changed)
738  m_selection_changed = true;
739 
741 
742  DisplayLibInfos();
743  }
744 
745  event.Skip(); // required under wxMAC
746 }
747 
748 
749 void LIB_VIEW_FRAME::CloseLibraryViewer( wxCommandEvent& event )
750 {
751  Close();
752 }
753 
754 
756 {
757  m_listPowerCmpOnly = false;
758  m_allowedLibs.Clear();
759 
760  if( aFilter )
761  {
762  m_allowedLibs = aFilter->GetAllowedLibList();
764  }
765 
766  ReCreateListLib();
767 }
768 
769 
771 {
772  LIB_PART* part = GetSelectedSymbol();
773 
774  if( !part )
775  {
776  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
777  }
778  else
779  {
780  std::shared_ptr< LIB_PART > tmp;
781 
782  tmp = ( part->IsAlias() ) ? part->GetParent().lock() : part->SharedPtr();
783 
784  wxCHECK( tmp, BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ) );
785 
786  EDA_RECT bbox = tmp->GetUnitBoundingBox( m_unit, m_convert );
787  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
788  }
789 }
790 
791 
793 {
794  if( m_cmpList->GetSelection() >= 0 )
795  DismissModal( true, m_libraryName + ':' + m_cmpList->GetStringSelection() );
796  else
797  DismissModal( false );
798 
799  Close( true );
800 }
801 
802 
803 
804 void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
805 {
806  std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock );
807 
808  // One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway.
809  if( !dialogLock.try_lock() )
810  return;
811 
812  // Container doing search-as-you-type.
813  SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
814  auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs ) );
815  auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
816 
817  const auto libNicknames = libs->GetLogicalLibs();
818  adapter->AddLibraries( libNicknames, this );
819 
820  LIB_PART* current = GetSelectedSymbol();
821  LIB_ID id;
822  int unit = 0;
823 
824  if( current )
825  {
826  id = current->GetLibId();
827  adapter->SetPreselectNode( id, unit );
828  }
829 
830  wxString dialogTitle;
831  dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
832 
833  DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, m_convert, false, false, false );
834 
835  if( dlg.ShowQuasiModal() == wxID_CANCEL )
836  return;
837 
838  id = dlg.GetSelectedLibId( &unit );
839 
840  if( !id.IsValid() )
841  return;
842 
843  SetSelectedLibrary( id.GetLibNickname() );
844  SetSelectedComponent( id.GetLibItemName() );
845  SetUnitAndConvert( unit, 1 );
846 }
847 
848 
849 void LIB_VIEW_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
850 {
851  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
852  int ii = m_cmpList->GetSelection();
853 
854  // Select the next symbol or stop at the end of the list.
855  if( ii != wxNOT_FOUND || ii != (int)m_cmpList->GetCount() - 1 )
856  ii += 1;
857 
858  m_cmpList->SetSelection( ii );
859  ProcessEvent( evt );
860 }
861 
862 
863 void LIB_VIEW_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
864 {
865  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
866  int ii = m_cmpList->GetSelection();
867 
868  // Select the previous symbol or stop at the beginning of list.
869  if( ii != wxNOT_FOUND && ii != 0 )
870  ii -= 1;
871 
872  m_cmpList->SetSelection( ii );
873  ProcessEvent( evt );
874 }
875 
876 
877 void LIB_VIEW_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
878 {
879  int ii = m_unitChoice->GetSelection();
880 
881  if( ii < 0 )
882  return;
883 
884  m_unit = ii + 1;
885 
887 }
888 
889 
891 {
892  if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
893  {
894  const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName );
895 
896  wxString title = wxString::Format( wxT( "%s \u2014 " ) + _( "Symbol Library Browser" ),
897  row ? row->GetFullURI() : _( "no library selected" ) );
898  SetTitle( title );
899  }
900 }
901 
902 
904 {
905  return m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
906 }
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
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.
static TOOL_ACTION showDatasheet
Inspection and Editing.
Definition: ee_actions.h:140
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:522
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
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.
LIB_FIELD & GetDatasheetField()
Return reference to the datasheet field.
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 setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
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...
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
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:375
int GetWidth() const
Definition: eda_rect.h:119
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:94
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:212
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
wxArrayString m_allowedLibs
wxAuiManager m_auimgr
static wxString m_libraryName
ACTION_TOOLBAR * m_mainToolBar
ACTION_MANAGER.
wxString GetKeyWords() const
#define CHECK(x)
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
static TOOL_ACTION showDeMorganAlternate
Definition: ee_actions.h:128
Class that groups generic conditions for editor states.
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...
Handle actions for the various symbol editor and viewers.
Definition: lib_control.h:37
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
#define ENABLE(x)
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:81
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:99
SELECTION_CONDITION GridVisible()
Creates a functor testing if the grid is visible in a frame.
#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.
static TOOL_ACTION toggleGrid
Definition: actions.h:138
bool m_Center
Center on screen.
Definition: base_screen.h:69
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.
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:51
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:167
COMMON_CONTROL.
void SetAxesEnabled(bool aAxesEnabled)
Enables drawing the axes.
virtual void ClearMsgPanel()
Clear all messages from the message panel.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
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)
static TOOL_ACTION showDeMorganStandard
Definition: ee_actions.h:127
bool IsModal() const override
Return true if the frame is shown in our modal mode and false if the frame is shown as an usual frame...
Definition: kiway_player.h:176
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
static TOOL_ACTION showElectricalTypes
Definition: ee_actions.h:201
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:52
EESCHEMA_ACTIONS.
Definition: ee_actions.h:41
COMMON_TOOLS.
Definition: common_tools.h:38
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:50
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:201
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
ACTION_MANAGER * GetActionManager()
Definition: tool_manager.h:199
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.
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
#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 SetOrigin(const Vec &pos)
Definition: box2.h:210
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
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
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:345
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:78
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.
static constexpr int Millimeter2iu(double mm)
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...
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127
#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.