KiCad PCB EDA Suite
symbol_viewer_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-2021 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 <symbol_library.h>
28 #include <confirm.h>
29 #include <dialog_choose_symbol.h>
30 #include <eeschema_id.h>
31 #include <eeschema_settings.h>
32 #include <kiface_base.h>
33 #include <kiway.h>
34 #include <symbol_viewer_frame.h>
35 #include <widgets/msgpanel.h>
36 #include <sch_view.h>
37 #include <sch_painter.h>
38 #include <symbol_lib_table.h>
40 #include <pgm_base.h>
42 #include <tool/action_toolbar.h>
43 #include <tool/common_control.h>
44 #include <tool/common_tools.h>
45 #include <tool/editor_conditions.h>
46 #include <tool/selection.h>
47 #include <tool/tool_dispatcher.h>
48 #include <tool/tool_manager.h>
49 #include <tool/zoom_tool.h>
50 #include <tools/ee_actions.h>
53 #include <view/view_controls.h>
54 #include <wx/listbox.h>
55 
56 #include <default_values.h>
57 #include <string_utils.h>
58 
59 // Save previous symbol library viewer state.
62 
65 
66 
67 BEGIN_EVENT_TABLE( SYMBOL_VIEWER_FRAME, EDA_DRAW_FRAME )
68  // Window events
69  EVT_SIZE( SYMBOL_VIEWER_FRAME::OnSize )
70  EVT_ACTIVATE( SYMBOL_VIEWER_FRAME::OnActivate )
71 
72  // Toolbar events
77 
78  // listbox events
82 
83  // Menu (and/or hotkey) events
84  EVT_MENU( wxID_CLOSE, SYMBOL_VIEWER_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 SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_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 ),
106  m_libList( nullptr ),
107  m_symbolList( nullptr ),
108  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 = _( "KiCad 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( BITMAPS::library_browser ) );
125  SetIcon( icon );
126 
127  m_libListWidth = 200;
128  m_symbolListWidth = 300;
129  m_listPowerOnly = 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  gal_opts.m_gridMinSpacing = 10.0;
139  gal_opts.NotifyChanged();
140 
143 
147 
148  setupTools();
150 
153  ReCreateMenuBar();
154 
155  m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
156  0, nullptr, wxLB_HSCROLL | wxNO_BORDER );
157 
158  m_symbolList = new wxListBox( this, ID_LIBVIEW_SYM_LIST, wxDefaultPosition, wxDefaultSize,
159  0, nullptr, wxLB_HSCROLL | wxNO_BORDER );
160 
161  if( aLibraryName.empty() )
162  {
163  ReCreateLibList();
164  }
165  else
166  {
167  m_libraryName = aLibraryName;
168  m_entryName.Clear();
169  m_unit = 1;
170  m_convert = 1;
171  }
172 
173  m_selection_changed = false;
174 
175  DisplayLibInfos();
176 
177  m_auimgr.SetManagedWindow( this );
178 
179  // Manage main toolbar
180  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer( 6 ) );
181  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
182  .Bottom().Layer( 6 ) );
183 
184  m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3)
185  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) );
186  m_auimgr.AddPane( m_symbolList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
187  .CaptionVisible( false ).MinSize( 80, -1 )
188  .BestSize( m_symbolListWidth, -1 ) );
189 
190  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
191 
192  m_auimgr.GetPane( m_libList ).Show( aLibraryName.empty() );
193 
194  m_auimgr.Update();
195 
196  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
197  {
198  Raise();
199  Show( true );
200  }
201 
202  SyncView();
203  GetCanvas()->SetCanFocus( false );
204 
205  setupUnits( config() );
206 
207  // Set the working/draw area size to display a symbol to a reasonable value:
208  // A 450mm x 450mm with a origin at the area center looks like a large working area
209  double max_size_x = Millimeter2iu( 450 );
210  double max_size_y = Millimeter2iu( 450 );
211  BOX2D bbox;
212  bbox.SetOrigin( -max_size_x / 2, -max_size_y / 2 );
213  bbox.SetSize( max_size_x, max_size_y );
214  GetCanvas()->GetView()->SetBoundary( bbox );
216 }
217 
218 
220 {
221  // Shutdown all running tools
222  if( m_toolManager )
224 
225  if( m_previewItem )
227 }
228 
229 
231 {
232  // Create the manager and dispatcher & route draw panel events to the dispatcher
235  GetCanvas()->GetViewControls(), config(), this );
236  m_actions = new EE_ACTIONS();
238 
239  // Register tools
243  m_toolManager->RegisterTool( new EE_INSPECTION_TOOL ); // manage show datasheet
244  m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); // manage context menu
246 
248 
249  // Run the selection tool, it is supposed to be always active
250  // It also manages the mouse right click to show the context menu
251  m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
252 
254 }
255 
256 
258 {
260 
262  EDITOR_CONDITIONS cond( this );
263 
264  wxASSERT( mgr );
265 
266 #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
267 #define CHECK( x ) ACTION_CONDITIONS().Check( x )
268 
270 
271  auto electricalTypesShownCondition =
272  [this] ( const SELECTION& aSel )
273  {
275  };
276 
277  auto demorganCond =
278  [this] ( const SELECTION& )
279  {
280  LIB_SYMBOL* symbol = GetSelectedSymbol();
281 
282  return symbol && symbol->HasConversion();
283  };
284 
285  auto demorganStandardCond =
286  [] ( const SELECTION& )
287  {
288  return m_convert == LIB_ITEM::LIB_CONVERT::BASE;
289  };
290 
291  auto demorganAlternateCond =
292  [] ( const SELECTION& )
293  {
294  return m_convert == LIB_ITEM::LIB_CONVERT::DEMORGAN;
295  };
296 
297  auto haveDatasheetCond =
298  [this] ( const SELECTION& )
299  {
300  LIB_SYMBOL* symbol = GetSelectedSymbol();
301 
302  return symbol && !symbol->GetDatasheetField().GetText().IsEmpty();
303  };
304 
305  mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
306  mgr->SetConditions( EE_ACTIONS::showElectricalTypes, CHECK( electricalTypesShownCondition ) );
307 
309  ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganStandardCond ) );
311  ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganAlternateCond ) );
312 
313 #undef CHECK
314 #undef ENABLE
315 }
316 
317 
318 void SYMBOL_VIEWER_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
319 {
320  m_unit = aUnit > 0 ? aUnit : 1;
321  m_convert = aConvert > 0 ? aConvert : LIB_ITEM::LIB_CONVERT::BASE;
322  m_selection_changed = false;
323 
325 }
326 
327 
329 {
330  LIB_SYMBOL* symbol = nullptr;
331 
332  if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
333  symbol = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
334 
335  return symbol;
336 }
337 
338 
340 {
341  LIB_SYMBOL* symbol = GetSelectedSymbol();
342  KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
343 
344  if( m_previewItem )
345  {
346  view->Remove( m_previewItem );
347  m_previewItem = nullptr;
348  }
349 
350  ClearMsgPanel();
351 
352  if( symbol )
353  {
356 
357  m_previewItem = symbol;
358  view->Add( m_previewItem );
359 
360  wxString parentName;
361  std::shared_ptr<LIB_SYMBOL> parent = m_previewItem->GetParent().lock();
362 
363  if( parent )
364  parentName = parent->GetName();
365 
367  AppendMsgPanel( _( "Parent" ), UnescapeString( parentName ) );
368  AppendMsgPanel( _( "Description" ), m_previewItem->GetDescription() );
369  AppendMsgPanel( _( "Keywords" ), m_previewItem->GetKeyWords() );
370  }
371 
372  GetCanvas()->ForceRefresh();
373 }
374 
375 
376 bool SYMBOL_VIEWER_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
377 {
378  if( aSymbol && !aSymbol->IsEmpty() )
379  {
380  wxString msg;
381  LIB_TABLE* libTable = Prj().SchSymbolLibTable();
382  LIB_ID libid;
383 
384  libid.Parse( *aSymbol, true );
385 
386  if( libid.IsValid() )
387  {
388  wxString libName = libid.GetLibNickname();
389 
390  if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
391  {
392  msg.Printf( _( "The current configuration does not include the library '%s'.\n"
393  "Use Manage Symbol Libraries to edit the configuration." ),
394  UnescapeString( libName ) );
395  DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
396  }
397  else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
398  {
399  msg.Printf( _( "The library '%s' is not enabled in the current configuration.\n"
400  "Use Manage Symbol Libraries to edit the configuration." ),
401  UnescapeString( libName ) );
402  DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
403  }
404  else
405  {
408  }
409  }
410  }
411 
412  return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
413 }
414 
415 
417 {
418  GetCanvas()->StopDrawing();
419 
420  if( !IsModal() )
421  {
422  Destroy();
423  }
424  else if( !IsDismissed() )
425  {
426  // only dismiss modal frame if not already dismissed.
427  DismissModal( false );
428 
429  // Modal frame will be destroyed by the calling function.
430  }
431 }
432 
433 
434 void SYMBOL_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
435 {
436  if( m_auimgr.GetManagedWindow() )
437  m_auimgr.Update();
438 
439  SizeEv.Skip();
440 }
441 
442 
443 void SYMBOL_VIEWER_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
444 {
445  LIB_SYMBOL* symbol = GetSelectedSymbol();
446 
447  int unit_count = 1;
448 
449  if( symbol )
450  unit_count = std::max( symbol->GetUnitCount(), 1 );
451 
452  m_unitChoice->Enable( unit_count > 1 );
453 
454  if( unit_count > 1 )
455  {
456  // rebuild the unit list if it is not suitable (after a new selection for instance)
457  if( unit_count != (int)m_unitChoice->GetCount() )
458  {
459  m_unitChoice->Clear();
460 
461  for( int ii = 0; ii < unit_count; ii++ )
462  m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
463 
464  }
465 
466  if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
467  m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
468  }
469  else if( m_unitChoice->GetCount() )
470  {
471  m_unitChoice->Clear();
472  }
473 }
474 
475 
477 {
478  if( !m_libList )
479  return false;
480 
481  m_libList->Clear();
482 
483  std::vector<wxString> libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
484 
485  // Remove not allowed libs from main list, if the allowed lib list is not empty
486  if( m_allowedLibs.GetCount() )
487  {
488  for( unsigned ii = 0; ii < libs.size(); )
489  {
490  if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
491  libs.erase( libs.begin() + ii );
492  else
493  ii++;
494  }
495  }
496 
497  // Remove libs which have no power symbols, if this filter is activated
498  if( m_listPowerOnly )
499  {
500  for( unsigned ii = 0; ii < libs.size(); )
501  {
502  wxArrayString aliasNames;
503 
504  Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
505 
506  if( aliasNames.IsEmpty() )
507  libs.erase( libs.begin() + ii );
508  else
509  ii++;
510  }
511  }
512 
513  if( libs.empty() )
514  return true;
515 
516  wxArrayString libNames;
517 
518  for( const auto& name : libs )
519  libNames.Add( UnescapeString( name ) );
520 
521  m_libList->Append( libNames );
522 
523  // Search for a previous selection:
524  int index = m_libList->FindString( UnescapeString( m_libraryName ) );
525 
526  if( index != wxNOT_FOUND )
527  {
528  m_libList->SetSelection( index, true );
529  }
530  else
531  {
532  // If not found, clear current library selection because it can be
533  // deleted after a config change.
534  m_libraryName = libs[0];
535  m_entryName = wxEmptyString;
536  m_unit = 1;
537  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
538  }
539 
540  bool cmp_changed = ReCreateSymbolList();
541  DisplayLibInfos();
542  GetCanvas()->Refresh();
543 
544  return cmp_changed;
545 }
546 
547 
549 {
550  if( m_symbolList == nullptr )
551  return false;
552 
553  wxArrayString aliasNames;
554 
555  try
556  {
557  Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
558  m_listPowerOnly );
559  }
560  catch( const IO_ERROR& ) {} // ignore, it is handled below
561 
562  m_symbolList->Clear();
563 
564  if( aliasNames.IsEmpty() )
565  {
566  m_libraryName = wxEmptyString;
567  m_entryName = wxEmptyString;
568  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
569  m_unit = 1;
570  return true;
571  }
572 
573  wxArrayString unescapedNames;
574 
575  for( const wxString& name : aliasNames )
576  unescapedNames.Add( UnescapeString( name ) );
577 
578  m_symbolList->Append( unescapedNames );
579 
580  int index = m_symbolList->FindString( UnescapeString( m_entryName ) );
581  bool changed = false;
582 
583  if( index == wxNOT_FOUND )
584  {
585  // Select the first library entry when the previous entry name does not exist in
586  // the current library.
587  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
588  m_unit = 1;
589  index = 0;
590  changed = true;
591  m_entryName = wxEmptyString;
592  }
593 
594  m_symbolList->SetSelection( index, true );
595 
596  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_SYM_LIST );
597  ProcessEvent( evt );
598 
599  return changed;
600 }
601 
602 
603 void SYMBOL_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event )
604 {
605  int ii = m_libList->GetSelection();
606 
607  if( ii < 0 )
608  return;
609 
610  m_selection_changed = true;
611 
612  SetSelectedLibrary( EscapeString( m_libList->GetString( ii ), CTX_LIBID ) );
613 }
614 
615 
616 void SYMBOL_VIEWER_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
617 {
618  if( m_libraryName == aLibraryName )
619  return;
620 
621  m_libraryName = aLibraryName;
623  GetCanvas()->Refresh();
624  DisplayLibInfos();
625 
626  // Ensure the corresponding line in m_libList is selected
627  // (which is not necessary the case if SetSelectedLibrary is called
628  // by another caller than ClickOnLibList.
629  m_libList->SetStringSelection( UnescapeString( m_libraryName ), true );
630 
631  // The m_libList has now the focus, in order to be able to use arrow keys
632  // to navigate inside the list.
633  // the gal canvas must not steal the focus to allow navigation
634  GetCanvas()->SetStealsFocus( false );
635  m_libList->SetFocus();
636 }
637 
638 
639 void SYMBOL_VIEWER_FRAME::ClickOnCmpList( wxCommandEvent& event )
640 {
641  int ii = m_symbolList->GetSelection();
642 
643  if( ii < 0 )
644  return;
645 
646  m_selection_changed = true;
647 
648  SetSelectedSymbol( EscapeString( m_symbolList->GetString( ii ), CTX_LIBID ) );
649 
650  // The m_symbolList has now the focus, in order to be able to use arrow keys
651  // to navigate inside the list.
652  // the gal canvas must not steal the focus to allow navigation
653  GetCanvas()->SetStealsFocus( false );
654  m_symbolList->SetFocus();
655 }
656 
657 
658 void SYMBOL_VIEWER_FRAME::SetSelectedSymbol( const wxString& aSymbolName )
659 {
660  if( m_entryName != aSymbolName )
661  {
662  m_entryName = aSymbolName;
663 
664  // Ensure the corresponding line in m_symbolList is selected
665  // (which is not necessarily the case if SetSelectedSymbol is called
666  // by another caller than ClickOnCmpList.
667  m_symbolList->SetStringSelection( UnescapeString( aSymbolName ), true );
668  DisplayLibInfos();
669 
670  if( m_selection_changed )
671  {
672  m_unit = 1;
673  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
674  m_selection_changed = false;
675  }
676 
679  }
680 }
681 
682 
683 void SYMBOL_VIEWER_FRAME::DClickOnCmpList( wxCommandEvent& event )
684 {
686 }
687 
688 
690 {
691  auto cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
692 
694 
695  // Grid shape, etc.
696  GetGalDisplayOptions().ReadWindowSettings( cfg->m_LibViewPanel.window );
697 
698  m_libListWidth = cfg->m_LibViewPanel.lib_list_width;
699  m_symbolListWidth = cfg->m_LibViewPanel.cmp_list_width;
700 
701  GetRenderSettings()->m_ShowPinsElectricalType = cfg->m_LibViewPanel.show_pin_electrical_type;
702 
703  // Set parameters to a reasonable value.
704  if( m_libListWidth > m_frameSize.x / 2 )
705  m_libListWidth = m_frameSize.x / 2;
706 
707  if( m_symbolListWidth > m_frameSize.x / 2 )
709 }
710 
711 
713 {
714  EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
715 
717 
718  if( m_libListWidth && m_libList )
719  m_libListWidth = m_libList->GetSize().x;
720 
721  m_symbolListWidth = m_symbolList->GetSize().x;
722 
726 }
727 
728 
730 {
731  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
732  wxASSERT( cfg );
733  return &cfg->m_LibViewPanel.window;
734 }
735 
736 
737 void SYMBOL_VIEWER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
738 {
739  SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
740 
742  GetCanvas()->GetGAL()->DrawGrid();
743 
744  if( aEnvVarsChanged )
745  ReCreateLibList();
746 }
747 
748 
749 void SYMBOL_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
750 {
751  if( event.GetActive() )
752  {
753  bool changed = m_libList ? ReCreateLibList() : false;
754 
755  if (changed)
756  m_selection_changed = true;
757 
759 
760  DisplayLibInfos();
761  }
762 
763  event.Skip(); // required under wxMAC
764 }
765 
766 
767 void SYMBOL_VIEWER_FRAME::CloseLibraryViewer( wxCommandEvent& event )
768 {
769  Close();
770 }
771 
772 
774 {
775  m_listPowerOnly = false;
776  m_allowedLibs.Clear();
777 
778  if( aFilter )
779  {
780  m_allowedLibs = aFilter->GetAllowedLibList();
782  }
783 
784  ReCreateLibList();
785 }
786 
787 
788 const BOX2I SYMBOL_VIEWER_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
789 {
790  LIB_SYMBOL* symbol = GetSelectedSymbol();
791 
792  if( !symbol )
793  {
794  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
795  }
796  else
797  {
798  std::shared_ptr< LIB_SYMBOL > tmp;
799 
800  tmp = ( symbol->IsAlias() ) ? symbol->GetParent().lock() : symbol->SharedPtr();
801 
802  wxCHECK( tmp, BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ) );
803 
804  EDA_RECT bbox = tmp->GetUnitBoundingBox( m_unit, m_convert );
805  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
806  }
807 }
808 
809 
811 {
812  if( m_symbolList->GetSelection() >= 0 )
813  {
814  DismissModal( true, m_libraryName + ':'
815  + EscapeString( m_symbolList->GetStringSelection(), CTX_LIBID ) );
816  }
817  else
818  {
819  DismissModal( false );
820  }
821 
822  Close( true );
823 }
824 
825 
826 void SYMBOL_VIEWER_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
827 {
828  std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_SYMBOL::g_Mutex, std::defer_lock );
829 
830  // One CHOOSE_SYMBOL dialog at a time. User probably can't handle more anyway.
831  if( !dialogLock.try_lock() )
832  return;
833 
834  // Container doing search-as-you-type.
835  SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
836  wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> adapter =
837  SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs );
838 
839  const auto libNicknames = libs->GetLogicalLibs();
840  static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapter.get() )->AddLibraries( libNicknames, this );
841 
842  LIB_SYMBOL* current = GetSelectedSymbol();
843  LIB_ID id;
844  int unit = 0;
845 
846  if( current )
847  {
848  id = current->GetLibId();
849  adapter->SetPreselectNode( id, unit );
850  }
851 
852  wxString dialogTitle;
853  dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
854 
855  DIALOG_CHOOSE_SYMBOL dlg( this, dialogTitle, adapter, m_convert, false, false, false );
856 
857  if( dlg.ShowQuasiModal() == wxID_CANCEL )
858  return;
859 
860  id = dlg.GetSelectedLibId( &unit );
861 
862  if( !id.IsValid() )
863  return;
864 
865  SetSelectedLibrary( id.GetLibNickname() );
866  SetSelectedSymbol( id.GetLibItemName() );
867  SetUnitAndConvert( unit, 1 );
868 }
869 
870 
871 void SYMBOL_VIEWER_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
872 {
873  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_SYM_LIST );
874  int ii = m_symbolList->GetSelection();
875 
876  // Select the next symbol or stop at the end of the list.
877  if( ii != wxNOT_FOUND || ii != (int) m_symbolList->GetCount() - 1 )
878  ii += 1;
879 
880  m_symbolList->SetSelection( ii );
881  ProcessEvent( evt );
882 }
883 
884 
885 void SYMBOL_VIEWER_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
886 {
887  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_SYM_LIST );
888  int ii = m_symbolList->GetSelection();
889 
890  // Select the previous symbol or stop at the beginning of list.
891  if( ii != wxNOT_FOUND && ii != 0 )
892  ii -= 1;
893 
894  m_symbolList->SetSelection( ii );
895  ProcessEvent( evt );
896 }
897 
898 
899 void SYMBOL_VIEWER_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
900 {
901  int ii = m_unitChoice->GetSelection();
902 
903  if( ii < 0 )
904  return;
905 
906  m_unit = ii + 1;
907 
909 }
910 
911 
913 {
914  if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
915  {
916  const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName, true );
917 
918  wxString title = row ? row->GetFullURI( true ) : _( "[no library selected]" );
919 
920  title += wxT( " \u2014 " ) + _( "Symbol Library Browser" );
921  SetTitle( title );
922  }
923 }
924 
925 
927 {
928  return m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
929 }
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
virtual bool ShowModal(wxString *aResult=nullptr, wxWindow *aResultantFocusWindow=nullptr)
Show this wxFrame as if it were a modal dialog, with all other instantiated wxFrames disabled until t...
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void ReCreateMenuBar() override
Recreates the menu bar.
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:124
static TOOL_ACTION showDatasheet
Inspection and Editing.
Definition: ee_actions.h:139
BOX2< VECTOR2I > BOX2I
Definition: box2.h:506
LIB_SYMBOL_SPTR SharedPtr() const
Definition: lib_symbol.h:107
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
void ForceRefresh()
Force a redraw.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
#define LIB_VIEW_NAME
This file is part of the common library.
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
bool IsDismissed()
wxString GetName() const override
Definition: lib_symbol.h:133
virtual void SetScreen(BASE_SCREEN *aScreen)
#define LIB_VIEW_STYLE
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
EVT_UPDATE_UI(ID_LOAD_FOOTPRINT_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadFootprintFromBoard) EVT_UPDATE_UI(ID_ADD_FOOTPRINT_TO_BOARD
void ClickOnCmpList(wxCommandEvent &event)
bool IsAlias() const
Definition: lib_symbol.h:172
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > Create(EDA_BASE_FRAME *aParent, LIB_TABLE *aLibs)
Factory function: create a model adapter in a reference-counting container.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:348
int GetWidth() const
Definition: eda_rect.h:109
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:96
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void SetSize(const Vec &size)
Definition: box2.h:195
Symbol library viewer main window.
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
static wxString m_entryName
wxAuiManager m_auimgr
ACTION_TOOLBAR * m_mainToolBar
Manage TOOL_ACTION objects.
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.
double m_gridMinSpacing
Whether or not to draw the coordinate system axes.
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Returns bbox of document with option to not include some items.
bool IsValid() const
Check if this LID_ID is valid.
Definition: lib_id.h:159
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
void onUpdateUnitChoice(wxUpdateUIEvent &aEvent)
Define a library symbol object.
Definition: lib_symbol.h:96
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
#define ENABLE(x)
static TOOL_ACTION showDeMorganAlternate
Definition: ee_actions.h:127
Class that groups generic conditions for editor states.
static std::mutex g_Mutex
bool InvokeTool(TOOL_ID aToolId)
Call a tool by sending a tool activation event to tool of given ID.
Dialog class to select a symbol from the libraries.
void OnSelectSymbol(wxCommandEvent &aEvent)
bool m_axesEnabled
Fullscreen crosshair or small cross.
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...
void CloseLibraryViewer(wxCommandEvent &event)
void onSelectNextSymbol(wxCommandEvent &aEvent)
void onSelectPreviousSymbol(wxCommandEvent &aEvent)
bool HasConversion() const
Test if symbol has more than one body conversion type (DeMorgan).
Master controller class:
Definition: tool_manager.h:54
void onSelectSymbolUnit(wxCommandEvent &aEvent)
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:81
void ReCreateHToolbar() override
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg) override
Return a pointer to the window settings for this frame.
wxString GetKeyWords() const
Definition: lib_symbol.h:155
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
static TOOL_ACTION toggleGrid
Definition: actions.h:140
bool m_Center
Center on screen.
Definition: base_screen.h:96
LIB_ID GetLibId() const override
Definition: lib_symbol.h:135
void SyncView()
Mark all items for refresh.
EDA_MSG_PANEL * m_messagePanel
const wxPoint GetOrigin() const
Definition: eda_rect.h:101
int ShowQuasiModal()
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
int GetUnitCount() const override
For items with units, return the number of units.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
void SetStealsFocus(bool aStealsFocus)
Set whether focus is taken on certain events (mouseover, keys, etc).
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
ACTIONS * m_actions
Definition: tools_holder.h:159
virtual void DrawGrid()
void SetSelectedSymbol(const wxString &aSymbolName)
Set the selected symbol.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
Definition for symbol library class.
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
#define _(s)
void SetUnitAndConvert(int aUnit, int aConvert)
Set unit and convert, and set flag preventing them from automatically resetting to 1.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:90
bool ReCreateLibList()
Create o recreates a sorted list of currently loaded libraries.
static TOOL_ACTION addSymbolToSchematic
Definition: ee_actions.h:166
void ReCreateVToolbar() override
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
Handle actions that are shared between different applications.
virtual void ClearMsgPanel()
Clear all messages from the message panel.
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
COLOR_SETTINGS * GetColorSettings() const override
Returns a pointer to the active color theme settings.
Specialization of the wxAuiPaneInfo class for KiCad panels.
static TOOL_ACTION showDeMorganStandard
Definition: ee_actions.h:126
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:173
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:202
int GetHeight() const
Definition: eda_rect.h:110
wxString UnescapeString(const wxString &aSource)
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:160
Gather all the actions that are shared by tools.
Definition: ee_actions.h:38
Handles action that are shared between different applications.
Definition: common_tools.h:37
COLOR_SETTINGS * m_colorSettings
The current canvas type.
void SetModal(bool aIsModal)
Definition: kiway_player.h:174
PANEL_LIB_VIEW m_LibViewPanel
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
bool m_selection_changed
Updated to true if a list rewrite on GUI activation resulted in the symbol selection changing,...
void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: sch_painter.cpp:92
COLOR4D GetColor(int aLayer) const
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:49
void SetFilter(const SCHLIB_FILTER *aFilter)
Set a filter to display only libraries and/or symbols which match the filter.
void OnActivate(wxActivateEvent &event)
Called when the frame is activated to reload the libraries and symbol lists that can be changed by th...
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:158
see class PGM_BASE
#define CHECK(x)
void SetSelectedLibrary(const wxString &aLibName)
Set the selected library in the library window.
const char * name
Definition: DXF_plotter.cpp:56
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)
Set the work environment (model, view, view controls and the parent window).
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
void DClickOnCmpList(wxCommandEvent &event)
void setupUnits(APP_SETTINGS_BASE *aCfg)
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
LIB_SYMBOL * GetSelectedSymbol() const
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SetOrigin(const Vec &pos)
Definition: box2.h:193
LIB_FIELD & GetDatasheetField()
Return reference to the datasheet field.
Handle the component boundary box.
Definition: eda_rect.h:42
#define IU_PER_MILS
Definition: plotter.cpp:136
const wxArrayString & GetAllowedLibList() const
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
void ClickOnLibList(wxCommandEvent &event)
ACTION_MANAGER * GetActionManager() const
Definition: tool_manager.h:199
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:318
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
void OnGridSettings(wxCommandEvent &event)
#define LIB_VIEW_NAME_MODAL
bool ShowModal(wxString *aSymbol, wxWindow *aParent) override
Runs the symbol viewer as a modal dialog.
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnSelectDisplayMode EVT_CHOICE(ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE, GERBVIEW_FRAME::OnSelectHighlightChoice) EVT_UPDATE_UI(ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
void InitTools()
Initializes all registered tools.
void doCloseWindow() override
void SetBoundary(const BOX2D &aBoundary)
Set limits for view area.
Definition: view.h:274
void SetDefaultPenWidth(int aWidth)
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
wxString GetDescription() override
Definition: lib_symbol.h:142
Message panel definition file.
Handle actions for the various symbol editor and viewers.
static wxString m_libraryName
static constexpr int Millimeter2iu(double mm)
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SYMBOL_VIEWER_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aLibraryName=wxEmptyString)
void FinishModal()
Send the selected symbol back to the caller.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
bool ProcessEvent(wxEvent &aEvent) override
Override the default process event handler to implement the auto save feature.
void StopDrawing()
Prevent the GAL canvas from further drawing until it is recreated or StartDrawing() is called.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
wxString m_aboutTitle
wxString m_configName
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
bool ReCreateSymbolList()
Create or recreate the list of symbols in the currently selected library.
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
bool GetFilterPowerSymbols() const
void AppendMsgPanel(const wxString &aTextUpper, const wxString &aTextLower, int aPadding=6)
Append a message to the message panel.
#define LIB_VIEW_STYLE_MODAL
void ReadWindowSettings(WINDOW_SETTINGS &aCfg)
Read GAL config options from application-level config.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.