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_helpers.h>
30 #include <dialog_choose_symbol.h>
31 #include <eeschema_id.h>
32 #include <eeschema_settings.h>
33 #include <kiface_i.h>
34 #include <kiway.h>
35 #include <symbol_viewer_frame.h>
36 #include <widgets/msgpanel.h>
37 #include <sch_view.h>
38 #include <sch_painter.h>
39 #include <symbol_lib_table.h>
41 #include <pgm_base.h>
43 #include <tool/action_toolbar.h>
44 #include <tool/common_control.h>
45 #include <tool/common_tools.h>
46 #include <tool/editor_conditions.h>
47 #include <tool/selection.h>
48 #include <tool/tool_dispatcher.h>
49 #include <tool/tool_manager.h>
50 #include <tool/zoom_tool.h>
51 #include <tools/ee_actions.h>
54 #include <view/view_controls.h>
55 #include <wx/listbox.h>
56 
57 #include <default_values.h>
58 #include <kicad_string.h>
59 
60 // Save previous symbol library viewer state.
63 
66 
67 
68 BEGIN_EVENT_TABLE( SYMBOL_VIEWER_FRAME, EDA_DRAW_FRAME )
69  // Window events
70  EVT_SIZE( SYMBOL_VIEWER_FRAME::OnSize )
71  EVT_ACTIVATE( SYMBOL_VIEWER_FRAME::OnActivate )
72 
73  // Toolbar events
78 
79  // listbox events
83 
84  // Menu (and/or hotkey) events
85  EVT_MENU( wxID_CLOSE, SYMBOL_VIEWER_FRAME::CloseLibraryViewer )
87 
89 
90 END_EVENT_TABLE()
91 
92 
93 #define LIB_VIEW_NAME "ViewlibFrame"
94 #define LIB_VIEW_NAME_MODAL "ViewlibFrameModal"
95 
96 #define LIB_VIEW_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
97 #define LIB_VIEW_STYLE_MODAL ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
98 
99 
100 SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
101  const wxString& aLibraryName ) :
102  SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Symbol Library Browser" ),
103  wxDefaultPosition, wxDefaultSize,
106  m_unitChoice( nullptr ),
107  m_libList( nullptr ),
108  m_symbolList( nullptr ),
109  m_previewItem( nullptr )
110 {
111  wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL );
112 
113  if( aFrameType == FRAME_SCH_VIEWER_MODAL )
114  SetModal( true );
115 
116  m_aboutTitle = _( "KiCad Symbol Library Viewer" );
117 
118  // Force the frame name used in config. the lib viewer frame has a name
119  // depending on aFrameType (needed to identify the frame by wxWidgets),
120  // but only one configuration is preferable.
122 
123  // Give an icon
124  wxIcon icon;
125  icon.CopyFromBitmap( KiBitmap( BITMAPS::library_browser ) );
126  SetIcon( icon );
127 
128  m_libListWidth = 200;
129  m_symbolListWidth = 300;
130  m_listPowerOnly = false;
131 
132  SetScreen( new SCH_SCREEN );
133  GetScreen()->m_Center = true; // Axis origin centered on screen.
134  LoadSettings( config() );
135 
136  // Ensure axis are always drawn (initial default display was not drawn)
138  gal_opts.m_axesEnabled = true;
139  gal_opts.m_gridMinSpacing = 10.0;
140  gal_opts.NotifyChanged();
141 
144 
148 
149  setupTools();
151 
154  ReCreateMenuBar();
155 
156  m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
157  0, nullptr, wxLB_HSCROLL | wxNO_BORDER );
158 
159  m_symbolList = new wxListBox( this, ID_LIBVIEW_SYM_LIST, wxDefaultPosition, wxDefaultSize,
160  0, nullptr, wxLB_HSCROLL | wxNO_BORDER );
161 
162  if( aLibraryName.empty() )
163  {
164  ReCreateLibList();
165  }
166  else
167  {
168  m_libraryName = aLibraryName;
169  m_entryName.Clear();
170  m_unit = 1;
171  m_convert = 1;
172  }
173 
174  m_selection_changed = false;
175 
176  DisplayLibInfos();
177 
178  m_auimgr.SetManagedWindow( this );
179 
180  // Manage main toolbar
181  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer( 6 ) );
182  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
183  .Bottom().Layer( 6 ) );
184 
185  m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3)
186  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) );
187  m_auimgr.AddPane( m_symbolList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
188  .CaptionVisible( false ).MinSize( 80, -1 )
189  .BestSize( m_symbolListWidth, -1 ) );
190 
191  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
192 
193  m_auimgr.GetPane( m_libList ).Show( aLibraryName.empty() );
194 
195  m_auimgr.Update();
196 
197  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
198  {
199  Raise();
200  Show( true );
201  }
202 
203  SyncView();
204  GetCanvas()->SetCanFocus( false );
205 
206  setupUnits( config() );
207 
208  // Set the working/draw area size to display a symbol to a reasonable value:
209  // A 450mm x 450mm with a origin at the area center looks like a large working area
210  double max_size_x = Millimeter2iu( 450 );
211  double max_size_y = Millimeter2iu( 450 );
212  BOX2D bbox;
213  bbox.SetOrigin( -max_size_x / 2, -max_size_y / 2 );
214  bbox.SetSize( max_size_x, max_size_y );
215  GetCanvas()->GetView()->SetBoundary( bbox );
217 }
218 
219 
221 {
222  // Shutdown all running tools
223  if( m_toolManager )
225 
226  if( m_previewItem )
228 }
229 
230 
232 {
233  // Create the manager and dispatcher & route draw panel events to the dispatcher
236  GetCanvas()->GetViewControls(), config(), this );
237  m_actions = new EE_ACTIONS();
239 
240  // Register tools
244  m_toolManager->RegisterTool( new EE_INSPECTION_TOOL ); // manage show datasheet
245  m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); // manage context menu
247 
249 
250  // Run the selection tool, it is supposed to be always active
251  // It also manages the mouse right click to show the context menu
252  m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
253 
255 }
256 
257 
259 {
261 
263  EDITOR_CONDITIONS cond( this );
264 
265  wxASSERT( mgr );
266 
267 #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
268 #define CHECK( x ) ACTION_CONDITIONS().Check( x )
269 
271 
272  auto electricalTypesShownCondition =
273  [this] ( const SELECTION& aSel )
274  {
276  };
277 
278  auto demorganCond =
279  [this] ( const SELECTION& )
280  {
281  LIB_SYMBOL* symbol = GetSelectedSymbol();
282 
283  return symbol && symbol->HasConversion();
284  };
285 
286  auto demorganStandardCond =
287  [] ( const SELECTION& )
288  {
289  return m_convert == LIB_ITEM::LIB_CONVERT::BASE;
290  };
291 
292  auto demorganAlternateCond =
293  [] ( const SELECTION& )
294  {
295  return m_convert == LIB_ITEM::LIB_CONVERT::DEMORGAN;
296  };
297 
298  auto haveDatasheetCond =
299  [this] ( const SELECTION& )
300  {
301  LIB_SYMBOL* symbol = GetSelectedSymbol();
302 
303  return symbol && !symbol->GetDatasheetField().GetText().IsEmpty();
304  };
305 
306  mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
307  mgr->SetConditions( EE_ACTIONS::showElectricalTypes, CHECK( electricalTypesShownCondition ) );
308 
310  ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganStandardCond ) );
312  ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganAlternateCond ) );
313 
314 #undef CHECK
315 #undef ENABLE
316 }
317 
318 
319 void SYMBOL_VIEWER_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
320 {
321  m_unit = aUnit > 0 ? aUnit : 1;
322  m_convert = aConvert > 0 ? aConvert : LIB_ITEM::LIB_CONVERT::BASE;
323  m_selection_changed = false;
324 
326 }
327 
328 
330 {
331  LIB_SYMBOL* symbol = nullptr;
332 
333  if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
334  symbol = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
335 
336  return symbol;
337 }
338 
339 
341 {
342  LIB_SYMBOL* symbol = GetSelectedSymbol();
343  KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
344 
345  if( m_previewItem )
346  {
347  view->Remove( m_previewItem );
348  m_previewItem = nullptr;
349  }
350 
351  ClearMsgPanel();
352 
353  if( symbol )
354  {
357 
358  m_previewItem = symbol;
359  view->Add( m_previewItem );
360 
361  wxString parentName;
362  std::shared_ptr<LIB_SYMBOL> parent = m_previewItem->GetParent().lock();
363 
364  if( parent )
365  parentName = parent->GetName();
366 
368  AppendMsgPanel( _( "Parent" ), UnescapeString( parentName ) );
369  AppendMsgPanel( _( "Description" ), m_previewItem->GetDescription() );
370  AppendMsgPanel( _( "Keywords" ), m_previewItem->GetKeyWords() );
371  }
372 
373  GetCanvas()->ForceRefresh();
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  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  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 
680  }
681 }
682 
683 
684 void SYMBOL_VIEWER_FRAME::DClickOnCmpList( wxCommandEvent& event )
685 {
687 }
688 
689 
691 {
692  auto cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
693 
695 
696  // Grid shape, etc.
697  GetGalDisplayOptions().ReadWindowSettings( cfg->m_LibViewPanel.window );
698 
699  m_libListWidth = cfg->m_LibViewPanel.lib_list_width;
700  m_symbolListWidth = cfg->m_LibViewPanel.cmp_list_width;
701 
702  GetRenderSettings()->m_ShowPinsElectricalType = cfg->m_LibViewPanel.show_pin_electrical_type;
703 
704  // Set parameters to a reasonable value.
705  if( m_libListWidth > m_frameSize.x / 2 )
706  m_libListWidth = m_frameSize.x / 2;
707 
708  if( m_symbolListWidth > m_frameSize.x / 2 )
710 }
711 
712 
714 {
715  EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
716 
718 
719  if( m_libListWidth && m_libList )
720  m_libListWidth = m_libList->GetSize().x;
721 
722  m_symbolListWidth = m_symbolList->GetSize().x;
723 
727 }
728 
729 
731 {
732  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
733  wxASSERT( cfg );
734  return &cfg->m_LibViewPanel.window;
735 }
736 
737 
738 void SYMBOL_VIEWER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
739 {
740  SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
741 
743  GetCanvas()->GetGAL()->DrawGrid();
744 
745  if( aEnvVarsChanged )
746  ReCreateLibList();
747 }
748 
749 
750 void SYMBOL_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
751 {
752  if( event.GetActive() )
753  {
754  bool changed = m_libList ? ReCreateLibList() : false;
755 
756  if (changed)
757  m_selection_changed = true;
758 
760 
761  DisplayLibInfos();
762  }
763 
764  event.Skip(); // required under wxMAC
765 }
766 
767 
768 void SYMBOL_VIEWER_FRAME::CloseLibraryViewer( wxCommandEvent& event )
769 {
770  Close();
771 }
772 
773 
775 {
776  m_listPowerOnly = false;
777  m_allowedLibs.Clear();
778 
779  if( aFilter )
780  {
781  m_allowedLibs = aFilter->GetAllowedLibList();
783  }
784 
785  ReCreateLibList();
786 }
787 
788 
789 const BOX2I SYMBOL_VIEWER_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
790 {
791  LIB_SYMBOL* symbol = GetSelectedSymbol();
792 
793  if( !symbol )
794  {
795  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
796  }
797  else
798  {
799  std::shared_ptr< LIB_SYMBOL > tmp;
800 
801  tmp = ( symbol->IsAlias() ) ? symbol->GetParent().lock() : symbol->SharedPtr();
802 
803  wxCHECK( tmp, BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ) );
804 
805  EDA_RECT bbox = tmp->GetUnitBoundingBox( m_unit, m_convert );
806  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
807  }
808 }
809 
810 
812 {
813  if( m_symbolList->GetSelection() >= 0 )
814  {
815  DismissModal( true, m_libraryName + ':'
816  + EscapeString( m_symbolList->GetStringSelection(), CTX_LIBID ) );
817  }
818  else
819  {
820  DismissModal( false );
821  }
822 
823  Close( true );
824 }
825 
826 
827 void SYMBOL_VIEWER_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
828 {
829  std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_SYMBOL::g_Mutex, std::defer_lock );
830 
831  // One CHOOSE_SYMBOL dialog at a time. User probably can't handle more anyway.
832  if( !dialogLock.try_lock() )
833  return;
834 
835  // Container doing search-as-you-type.
836  SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
837  wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> adapter =
838  SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs );
839 
840  const auto libNicknames = libs->GetLogicalLibs();
841  static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapter.get() )->AddLibraries( libNicknames, this );
842 
843  LIB_SYMBOL* current = GetSelectedSymbol();
844  LIB_ID id;
845  int unit = 0;
846 
847  if( current )
848  {
849  id = current->GetLibId();
850  adapter->SetPreselectNode( id, unit );
851  }
852 
853  wxString dialogTitle;
854  dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
855 
856  DIALOG_CHOOSE_SYMBOL dlg( this, dialogTitle, adapter, m_convert, false, false, false );
857 
858  if( dlg.ShowQuasiModal() == wxID_CANCEL )
859  return;
860 
861  id = dlg.GetSelectedLibId( &unit );
862 
863  if( !id.IsValid() )
864  return;
865 
866  SetSelectedLibrary( id.GetLibNickname() );
867  SetSelectedSymbol( id.GetLibItemName() );
868  SetUnitAndConvert( unit, 1 );
869 }
870 
871 
872 void SYMBOL_VIEWER_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
873 {
874  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_SYM_LIST );
875  int ii = m_symbolList->GetSelection();
876 
877  // Select the next symbol or stop at the end of the list.
878  if( ii != wxNOT_FOUND || ii != (int) m_symbolList->GetCount() - 1 )
879  ii += 1;
880 
881  m_symbolList->SetSelection( ii );
882  ProcessEvent( evt );
883 }
884 
885 
886 void SYMBOL_VIEWER_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
887 {
888  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_SYM_LIST );
889  int ii = m_symbolList->GetSelection();
890 
891  // Select the previous symbol or stop at the beginning of list.
892  if( ii != wxNOT_FOUND && ii != 0 )
893  ii -= 1;
894 
895  m_symbolList->SetSelection( ii );
896  ProcessEvent( evt );
897 }
898 
899 
900 void SYMBOL_VIEWER_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
901 {
902  int ii = m_unitChoice->GetSelection();
903 
904  if( ii < 0 )
905  return;
906 
907  m_unit = ii + 1;
908 
910 }
911 
912 
914 {
915  if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
916  {
917  const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName, true );
918 
919  wxString title = row ? row->GetFullURI( true ) : _( "[no library selected]" );
920 
921  title += wxT( " \u2014 " ) + _( "Symbol Library Browser" );
922  SetTitle( title );
923  }
924 }
925 
926 
928 {
929  return m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
930 }
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:136
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:265
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.
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:351
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:124
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.
Helper dialog and control classes.
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:163
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.
#define DEFAULT_LINE_THICKNESS
The default wire width in mils. (can be changed in preference menu)
static TOOL_ACTION showDeMorganStandard
Definition: ee_actions.h:123
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:199
int GetHeight() const
Definition: eda_rect.h:110
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:94
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:59
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)
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:222
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
Definition: string.cpp:141
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:137
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:321
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
void InitTools()
Initializes all registered tools.
void doCloseWindow() override
void SetBoundary(const BOX2D &aBoundary)
Set limits for view area.
Definition: view.h:273
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.