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 <[email protected]>
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( wxT( "MainToolbar" ) ).Top().Layer( 6 ) );
181  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( wxT( "MsgPanel" ) )
182  .Bottom().Layer( 6 ) );
183 
184  m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( wxT( "Libraries" ) ).Left().Layer(3)
185  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) );
186  m_auimgr.AddPane( m_symbolList, EDA_PANE().Palette().Name( wxT( "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( wxT( "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 
373  GetCanvas()->Refresh();
374 }
375 
376 
377 bool SYMBOL_VIEWER_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
378 {
379  if( aSymbol && !aSymbol->IsEmpty() )
380  {
381  wxString msg;
382  LIB_TABLE* libTable = Prj().SchSymbolLibTable();
383  LIB_ID libid;
384 
385  libid.Parse( *aSymbol, true );
386 
387  if( libid.IsValid() )
388  {
389  wxString libName = libid.GetLibNickname();
390 
391  if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
392  {
393  msg.Printf( _( "The current configuration does not include the library '%s'.\n"
394  "Use Manage Symbol Libraries to edit the configuration." ),
395  UnescapeString( libName ) );
396  DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
397  }
398  else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
399  {
400  msg.Printf( _( "The library '%s' is not enabled in the current configuration.\n"
401  "Use Manage Symbol Libraries to edit the configuration." ),
402  UnescapeString( libName ) );
403  DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
404  }
405  else
406  {
409  }
410  }
411  }
412 
413  return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
414 }
415 
416 
418 {
419  GetCanvas()->StopDrawing();
420 
421  if( !IsModal() )
422  {
423  Destroy();
424  }
425  else if( !IsDismissed() )
426  {
427  // only dismiss modal frame if not already dismissed.
428  DismissModal( false );
429 
430  // Modal frame will be destroyed by the calling function.
431  }
432 }
433 
434 
435 void SYMBOL_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
436 {
437  if( m_auimgr.GetManagedWindow() )
438  m_auimgr.Update();
439 
440  SizeEv.Skip();
441 }
442 
443 
444 void SYMBOL_VIEWER_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
445 {
446  LIB_SYMBOL* symbol = GetSelectedSymbol();
447 
448  int unit_count = 1;
449 
450  if( symbol )
451  unit_count = std::max( symbol->GetUnitCount(), 1 );
452 
453  m_unitChoice->Enable( unit_count > 1 );
454 
455  if( unit_count > 1 )
456  {
457  // rebuild the unit list if it is not suitable (after a new selection for instance)
458  if( unit_count != (int)m_unitChoice->GetCount() )
459  {
460  m_unitChoice->Clear();
461 
462  for( int ii = 0; ii < unit_count; ii++ )
463  m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
464 
465  }
466 
467  if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
468  m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
469  }
470  else if( m_unitChoice->GetCount() )
471  {
472  m_unitChoice->Clear();
473  }
474 }
475 
476 
478 {
479  if( !m_libList )
480  return false;
481 
482  m_libList->Clear();
483 
484  std::vector<wxString> libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
485 
486  // Remove not allowed libs from main list, if the allowed lib list is not empty
487  if( m_allowedLibs.GetCount() )
488  {
489  for( unsigned ii = 0; ii < libs.size(); )
490  {
491  if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
492  libs.erase( libs.begin() + ii );
493  else
494  ii++;
495  }
496  }
497 
498  // Remove libs which have no power symbols, if this filter is activated
499  if( m_listPowerOnly )
500  {
501  for( unsigned ii = 0; ii < libs.size(); )
502  {
503  wxArrayString aliasNames;
504 
505  Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
506 
507  if( aliasNames.IsEmpty() )
508  libs.erase( libs.begin() + ii );
509  else
510  ii++;
511  }
512  }
513 
514  if( libs.empty() )
515  return true;
516 
517  wxArrayString libNames;
518 
519  for( const auto& name : libs )
520  libNames.Add( UnescapeString( name ) );
521 
522  m_libList->Append( libNames );
523 
524  // Search for a previous selection:
525  int index = m_libList->FindString( UnescapeString( m_libraryName ) );
526 
527  if( index != wxNOT_FOUND )
528  {
529  m_libList->SetSelection( index, true );
530  }
531  else
532  {
533  // If not found, clear current library selection because it can be
534  // deleted after a config change.
535  m_libraryName = libs[0];
536  m_entryName = wxEmptyString;
537  m_unit = 1;
538  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
539  }
540 
541  bool cmp_changed = ReCreateSymbolList();
542  DisplayLibInfos();
543  GetCanvas()->Refresh();
544 
545  return cmp_changed;
546 }
547 
548 
550 {
551  if( m_symbolList == nullptr )
552  return false;
553 
554  wxArrayString aliasNames;
555 
556  try
557  {
558  Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
559  m_listPowerOnly );
560  }
561  catch( const IO_ERROR& ) {} // ignore, it is handled below
562 
563  m_symbolList->Clear();
564 
565  if( aliasNames.IsEmpty() )
566  {
567  m_libraryName = wxEmptyString;
568  m_entryName = wxEmptyString;
569  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
570  m_unit = 1;
571  return true;
572  }
573 
574  wxArrayString unescapedNames;
575 
576  for( const wxString& name : aliasNames )
577  unescapedNames.Add( UnescapeString( name ) );
578 
579  m_symbolList->Append( unescapedNames );
580 
581  int index = m_symbolList->FindString( UnescapeString( m_entryName ) );
582  bool changed = false;
583 
584  if( index == wxNOT_FOUND )
585  {
586  // Select the first library entry when the previous entry name does not exist in
587  // the current library.
588  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
589  m_unit = 1;
590  index = 0;
591  changed = true;
592  m_entryName = wxEmptyString;
593  }
594 
595  m_symbolList->SetSelection( index, true );
596 
597  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_SYM_LIST );
598  ProcessEvent( evt );
599 
600  return changed;
601 }
602 
603 
604 void SYMBOL_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event )
605 {
606  int ii = m_libList->GetSelection();
607 
608  if( ii < 0 )
609  return;
610 
611  m_selection_changed = true;
612 
613  SetSelectedLibrary( EscapeString( m_libList->GetString( ii ), CTX_LIBID ) );
614 }
615 
616 
617 void SYMBOL_VIEWER_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
618 {
619  if( m_libraryName == aLibraryName )
620  return;
621 
622  m_libraryName = aLibraryName;
624  GetCanvas()->Refresh();
625  DisplayLibInfos();
626 
627  // Ensure the corresponding line in m_libList is selected
628  // (which is not necessary the case if SetSelectedLibrary is called
629  // by another caller than ClickOnLibList.
630  m_libList->SetStringSelection( UnescapeString( m_libraryName ), true );
631 
632  // The m_libList has now the focus, in order to be able to use arrow keys
633  // to navigate inside the list.
634  // the gal canvas must not steal the focus to allow navigation
635  GetCanvas()->SetStealsFocus( false );
636  m_libList->SetFocus();
637 }
638 
639 
640 void SYMBOL_VIEWER_FRAME::ClickOnCmpList( wxCommandEvent& event )
641 {
642  int ii = m_symbolList->GetSelection();
643 
644  if( ii < 0 )
645  return;
646 
647  m_selection_changed = true;
648 
649  SetSelectedSymbol( EscapeString( m_symbolList->GetString( ii ), CTX_LIBID ) );
650 
651  // The m_symbolList has now the focus, in order to be able to use arrow keys
652  // to navigate inside the list.
653  // the gal canvas must not steal the focus to allow navigation
654  GetCanvas()->SetStealsFocus( false );
655  m_symbolList->SetFocus();
656 }
657 
658 
659 void SYMBOL_VIEWER_FRAME::SetSelectedSymbol( const wxString& aSymbolName )
660 {
661  if( m_entryName != aSymbolName )
662  {
663  m_entryName = aSymbolName;
664 
665  // Ensure the corresponding line in m_symbolList is selected
666  // (which is not necessarily the case if SetSelectedSymbol is called
667  // by another caller than ClickOnCmpList.
668  m_symbolList->SetStringSelection( UnescapeString( aSymbolName ), true );
669  DisplayLibInfos();
670 
671  if( m_selection_changed )
672  {
673  m_unit = 1;
674  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
675  m_selection_changed = false;
676  }
677 
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 
725 
726  if( GetRenderSettings() )
728 }
729 
730 
732 {
733  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
734  wxASSERT( cfg );
735  return &cfg->m_LibViewPanel.window;
736 }
737 
738 
739 void SYMBOL_VIEWER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
740 {
741  SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
742 
744  GetCanvas()->GetGAL()->DrawGrid();
745 
746  if( aEnvVarsChanged )
747  ReCreateLibList();
748 }
749 
750 
751 void SYMBOL_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
752 {
753  if( event.GetActive() )
754  {
755  bool changed = m_libList ? ReCreateLibList() : false;
756 
757  if (changed)
758  m_selection_changed = true;
759 
761 
762  DisplayLibInfos();
763  }
764 
765  event.Skip(); // required under wxMAC
766 }
767 
768 
769 void SYMBOL_VIEWER_FRAME::CloseLibraryViewer( wxCommandEvent& event )
770 {
771  Close();
772 }
773 
774 
776 {
777  m_listPowerOnly = false;
778  m_allowedLibs.Clear();
779 
780  if( aFilter )
781  {
782  m_allowedLibs = aFilter->GetAllowedLibList();
784  }
785 
786  ReCreateLibList();
787 }
788 
789 
790 const BOX2I SYMBOL_VIEWER_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
791 {
792  LIB_SYMBOL* symbol = GetSelectedSymbol();
793 
794  if( !symbol )
795  {
796  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
797  }
798  else
799  {
800  std::shared_ptr< LIB_SYMBOL > tmp;
801 
802  tmp = ( symbol->IsAlias() ) ? symbol->GetParent().lock() : symbol->SharedPtr();
803 
804  wxCHECK( tmp, BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ) );
805 
806  EDA_RECT bbox = tmp->GetUnitBoundingBox( m_unit, m_convert );
807  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
808  }
809 }
810 
811 
813 {
814  if( m_symbolList->GetSelection() >= 0 )
815  {
816  DismissModal( true, m_libraryName + ':'
817  + EscapeString( m_symbolList->GetStringSelection(), CTX_LIBID ) );
818  }
819  else
820  {
821  DismissModal( false );
822  }
823 
824  Close( true );
825 }
826 
827 
828 void SYMBOL_VIEWER_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
829 {
830  std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_SYMBOL::g_Mutex, std::defer_lock );
831 
832  // One CHOOSE_SYMBOL dialog at a time. User probably can't handle more anyway.
833  if( !dialogLock.try_lock() )
834  return;
835 
836  // Container doing search-as-you-type.
837  SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
838  wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> dataPtr
839  = SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs );
840  SYMBOL_TREE_MODEL_ADAPTER* modelAdapter
841  = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( dataPtr.get() );
842 
843  if( !modelAdapter->AddLibraries( libs->GetLogicalLibs(), this ) )
844  {
845  // loading cancelled by user
846  return;
847  }
848 
849  LIB_SYMBOL* current = GetSelectedSymbol();
850  LIB_ID id;
851  int unit = 0;
852 
853  if( current )
854  {
855  id = current->GetLibId();
856  modelAdapter->SetPreselectNode( id, unit );
857  }
858 
859  wxString dialogTitle;
860  dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), modelAdapter->GetItemCount() );
861 
862  DIALOG_CHOOSE_SYMBOL dlg( this, dialogTitle, dataPtr, m_convert, false, false, false );
863 
864  if( dlg.ShowQuasiModal() == wxID_CANCEL )
865  return;
866 
867  id = dlg.GetSelectedLibId( &unit );
868 
869  if( !id.IsValid() )
870  return;
871 
872  SetSelectedLibrary( id.GetLibNickname() );
873  SetSelectedSymbol( id.GetLibItemName() );
874  SetUnitAndConvert( unit, 1 );
875 }
876 
877 
878 void SYMBOL_VIEWER_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
879 {
880  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_SYM_LIST );
881  int ii = m_symbolList->GetSelection();
882 
883  // Select the next symbol or stop at the end of the list.
884  if( ii != wxNOT_FOUND || ii != (int) m_symbolList->GetCount() - 1 )
885  ii += 1;
886 
887  m_symbolList->SetSelection( ii );
888  ProcessEvent( evt );
889 }
890 
891 
892 void SYMBOL_VIEWER_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
893 {
894  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_SYM_LIST );
895  int ii = m_symbolList->GetSelection();
896 
897  // Select the previous symbol or stop at the beginning of list.
898  if( ii != wxNOT_FOUND && ii != 0 )
899  ii -= 1;
900 
901  m_symbolList->SetSelection( ii );
902  ProcessEvent( evt );
903 }
904 
905 
906 void SYMBOL_VIEWER_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
907 {
908  int ii = m_unitChoice->GetSelection();
909 
910  if( ii < 0 )
911  return;
912 
913  m_unit = ii + 1;
914 
916 }
917 
918 
920 {
921  if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
922  {
923  const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName, true );
924 
925  wxString title = row ? row->GetFullURI( true ) : _( "[no library selected]" );
926 
927  title += wxT( " \u2014 " ) + _( "Symbol Library Browser" );
928  SetTitle( title );
929  }
930 }
931 
932 
934 {
935  return m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
936 }
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:140
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...
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
void SetPreselectNode(const LIB_ID &aLibId, int aUnit)
Set the symbol name to be selected if there are no search results.
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:350
int GetWidth() const
Definition: eda_rect.h:118
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:622
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:128
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
int GetItemCount() const
Return the number of symbols loaded in the tree.
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:110
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:168
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: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: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:204
int GetHeight() const
Definition: eda_rect.h:119
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:90
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:130
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:320
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:154
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
bool AddLibraries(const std::vector< wxString > &aNicknames, wxWindow *aParent)
Add all the libraries in a SYMBOL_LIB_TABLE to the model.
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.