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-2019 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <bitmaps.h>
27 #include <class_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 
56 #include <default_values.h>
57 
58 // Save previous component library viewer state.
61 
64 
65 
66 BEGIN_EVENT_TABLE( SYMBOL_VIEWER_FRAME, EDA_DRAW_FRAME )
67  // Window events
68  EVT_SIZE( SYMBOL_VIEWER_FRAME::OnSize )
69  EVT_ACTIVATE( SYMBOL_VIEWER_FRAME::OnActivate )
70 
71  // Toolbar events
76 
77  // listbox events
81 
82  // Menu (and/or hotkey) events
83  EVT_MENU( wxID_CLOSE, SYMBOL_VIEWER_FRAME::CloseLibraryViewer )
85 
87 
88 END_EVENT_TABLE()
89 
90 
91 #define LIB_VIEW_NAME "ViewlibFrame"
92 #define LIB_VIEW_NAME_MODAL "ViewlibFrameModal"
93 
94 #define LIB_VIEW_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
95 #define LIB_VIEW_STYLE_MODAL ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
96 
97 
98 SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
99  const wxString& aLibraryName ) :
100  SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Symbol Library Browser" ),
101  wxDefaultPosition, wxDefaultSize,
104  m_unitChoice( nullptr ),
105  m_libList( nullptr ),
106  m_symbolList( nullptr ),
107  m_previewItem( nullptr )
108 {
109  wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL );
110 
111  if( aFrameType == FRAME_SCH_VIEWER_MODAL )
112  SetModal( true );
113 
114  m_aboutTitle = _( "KiCad Symbol Library Viewer" );
115 
116  // Force the frame name used in config. the lib viewer frame has a name
117  // depending on aFrameType (needed to identify the frame by wxWidgets),
118  // but only one configuration is preferable.
120 
121  // Give an icon
122  wxIcon icon;
123  icon.CopyFromBitmap( KiBitmap( BITMAPS::library_browser ) );
124  SetIcon( icon );
125 
126  m_libListWidth = 200;
127  m_symbolListWidth = 300;
128  m_listPowerCmpOnly = false;
129 
130  SetScreen( new SCH_SCREEN );
131  GetScreen()->m_Center = true; // Axis origin centered on screen.
132  LoadSettings( config() );
133 
134  // Ensure axis are always drawn (initial default display was not drawn)
136  gal_opts.m_axesEnabled = true;
137  gal_opts.m_gridMinSpacing = 10.0;
138  gal_opts.NotifyChanged();
139 
142 
146 
147  setupTools();
149 
152  ReCreateMenuBar();
153 
154  m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
155  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
156 
157  m_symbolList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxDefaultPosition, wxDefaultSize,
158  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
159 
160  if( aLibraryName.empty() )
161  {
162  ReCreateLibList();
163  }
164  else
165  {
166  m_libraryName = aLibraryName;
167  m_entryName.Clear();
168  m_unit = 1;
169  m_convert = 1;
170  }
171 
172  m_selection_changed = false;
173 
174  DisplayLibInfos();
175 
176  m_auimgr.SetManagedWindow( this );
177 
178  // Manage main toolbar
179  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
180  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
181 
182  m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3)
183  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) );
184  m_auimgr.AddPane( m_symbolList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
185  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_symbolListWidth, -1 ) );
186 
187  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
188 
189  m_auimgr.GetPane( m_libList ).Show( aLibraryName.empty() );
190 
191  m_auimgr.Update();
192 
193  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
194  {
195  Raise();
196  Show( true );
197  }
198 
199  SyncView();
200  GetCanvas()->SetCanFocus( false );
201 
202  setupUnits( config() );
203 
204  // Set the working/draw area size to display a symbol to a reasonable value:
205  // A 450mm x 450mm with a origin at the area center looks like a large working area
206  double max_size_x = Millimeter2iu( 450 );
207  double max_size_y = Millimeter2iu( 450 );
208  BOX2D bbox;
209  bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
210  bbox.SetSize( max_size_x, max_size_y );
211  GetCanvas()->GetView()->SetBoundary( bbox );
213 }
214 
215 
217 {
218  // Shutdown all running tools
219  if( m_toolManager )
221 
222  if( m_previewItem )
224 }
225 
226 
228 {
229  // Create the manager and dispatcher & route draw panel events to the dispatcher
232  GetCanvas()->GetViewControls(), config(), this );
233  m_actions = new EE_ACTIONS();
235 
236  // Register tools
240  m_toolManager->RegisterTool( new EE_INSPECTION_TOOL ); // manage show datasheet
241  m_toolManager->RegisterTool( new EE_SELECTION_TOOL ); // manage context menu
243 
245 
246  // Run the selection tool, it is supposed to be always active
247  // It also manages the mouse right click to show the context menu
248  m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
249 
251 }
252 
253 
255 {
257 
259  EDITOR_CONDITIONS cond( this );
260 
261  wxASSERT( mgr );
262 
263 #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
264 #define CHECK( x ) ACTION_CONDITIONS().Check( x )
265 
267 
268  auto electricalTypesShownCondition =
269  [this] ( const SELECTION& aSel )
270  {
272  };
273 
274  auto demorganCond =
275  [this] ( const SELECTION& )
276  {
277  LIB_PART* symbol = GetSelectedSymbol();
278 
279  return symbol && symbol->HasConversion();
280  };
281 
282  auto demorganStandardCond =
283  [] ( const SELECTION& )
284  {
285  return m_convert == LIB_ITEM::LIB_CONVERT::BASE;
286  };
287 
288  auto demorganAlternateCond =
289  [] ( const SELECTION& )
290  {
291  return m_convert == LIB_ITEM::LIB_CONVERT::DEMORGAN;
292  };
293 
294  auto haveDatasheetCond =
295  [this] ( const SELECTION& )
296  {
297  LIB_PART* symbol = GetSelectedSymbol();
298 
299  return symbol && !symbol->GetDatasheetField().GetText().IsEmpty();
300  };
301 
302  mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
303  mgr->SetConditions( EE_ACTIONS::showElectricalTypes, CHECK( electricalTypesShownCondition ) );
304 
306  ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganStandardCond ) );
308  ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganAlternateCond ) );
309 
310 #undef CHECK
311 #undef ENABLE
312 }
313 
314 
315 void SYMBOL_VIEWER_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
316 {
317  m_unit = aUnit > 0 ? aUnit : 1;
318  m_convert = aConvert > 0 ? aConvert : LIB_ITEM::LIB_CONVERT::BASE;
319  m_selection_changed = false;
320 
322 }
323 
324 
326 {
327  LIB_PART* symbol = nullptr;
328 
329  if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
330  symbol = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
331 
332  return symbol;
333 }
334 
335 
337 {
338  LIB_PART* symbol = GetSelectedSymbol();
339  KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
340 
341  if( m_previewItem )
342  {
343  view->Remove( m_previewItem );
344  m_previewItem = nullptr;
345  }
346 
347  ClearMsgPanel();
348 
349  if( symbol )
350  {
353 
354  m_previewItem = symbol;
355  view->Add( m_previewItem );
356 
357  wxString parentName;
358  std::shared_ptr<LIB_PART> parent = m_previewItem->GetParent().lock();
359 
360  if( parent )
361  parentName = parent->GetName();
362 
363  AppendMsgPanel( _( "Name" ), m_previewItem->GetName() );
364  AppendMsgPanel( _( "Parent" ), parentName );
365  AppendMsgPanel( _( "Description" ), m_previewItem->GetDescription() );
366  AppendMsgPanel( _( "Keywords" ), m_previewItem->GetKeyWords() );
367  }
368 
369  GetCanvas()->ForceRefresh();
370 }
371 
372 
373 bool SYMBOL_VIEWER_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
374 {
375  if( aSymbol && !aSymbol->IsEmpty() )
376  {
377  wxString msg;
378  LIB_TABLE* libTable = Prj().SchSymbolLibTable();
379  LIB_ID libid;
380 
381  libid.Parse( *aSymbol, true );
382 
383  if( libid.IsValid() )
384  {
385  wxString libName = libid.GetLibNickname();
386 
387  if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
388  {
389  msg.Printf( _( "The current configuration does not include the library '%s'.\n"
390  "Use Manage Symbol Libraries to edit the configuration." ),
391  libName );
392  DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
393  }
394  else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
395  {
396  msg.Printf( _( "The library '%s' is not enabled in the current configuration.\n"
397  "Use Manage Symbol Libraries to edit the configuration." ),
398  libName );
399  DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
400  }
401  else
402  {
405  }
406  }
407  }
408 
409  return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
410 }
411 
412 
414 {
415  GetCanvas()->StopDrawing();
416 
417  if( !IsModal() )
418  {
419  Destroy();
420  }
421  else if( !IsDismissed() )
422  {
423  // only dismiss modal frame if not already dismissed.
424  DismissModal( false );
425 
426  // Modal frame will be destroyed by the calling function.
427  }
428 }
429 
430 
431 void SYMBOL_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
432 {
433  if( m_auimgr.GetManagedWindow() )
434  m_auimgr.Update();
435 
436  SizeEv.Skip();
437 }
438 
439 
440 void SYMBOL_VIEWER_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
441 {
442  LIB_PART* part = GetSelectedSymbol();
443 
444  int unit_count = 1;
445 
446  if( part )
447  unit_count = std::max( part->GetUnitCount(), 1 );
448 
449  m_unitChoice->Enable( unit_count > 1 );
450 
451  if( unit_count > 1 )
452  {
453  // rebuild the unit list if it is not suitable (after a new selection for instance)
454  if( unit_count != (int)m_unitChoice->GetCount() )
455  {
456  m_unitChoice->Clear();
457 
458  for( int ii = 0; ii < unit_count; ii++ )
459  m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
460 
461  }
462 
463  if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
464  m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
465  }
466  else if( m_unitChoice->GetCount() )
467  m_unitChoice->Clear();
468 }
469 
470 
472 {
473  if( !m_libList )
474  return false;
475 
476  m_libList->Clear();
477 
478  std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
479 
480  // Remove not allowed libs from main list, if the allowed lib list is not empty
481  if( m_allowedLibs.GetCount() )
482  {
483  for( unsigned ii = 0; ii < libs.size(); )
484  {
485  if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
486  libs.erase( libs.begin() + ii );
487  else
488  ii++;
489  }
490  }
491 
492  // Remove libs which have no power components, if this filter is activated
493  if( m_listPowerCmpOnly )
494  {
495  for( unsigned ii = 0; ii < libs.size(); )
496  {
497  wxArrayString aliasNames;
498 
499  Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
500 
501  if( aliasNames.IsEmpty() )
502  libs.erase( libs.begin() + ii );
503  else
504  ii++;
505  }
506  }
507 
508  if( libs.empty() )
509  return true;
510 
511  wxArrayString libNames;
512 
513  for( const auto& name : libs )
514  libNames.Add( name );
515 
516  m_libList->Append( libNames );
517 
518  // Search for a previous selection:
519  int index = m_libList->FindString( m_libraryName );
520 
521  if( index != wxNOT_FOUND )
522  {
523  m_libList->SetSelection( index, true );
524  }
525  else
526  {
527  // If not found, clear current library selection because it can be
528  // deleted after a config change.
529  m_libraryName = libs[0];
530  m_entryName = wxEmptyString;
531  m_unit = 1;
532  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
533  }
534 
535  bool cmp_changed = ReCreateSymbolList();
536  DisplayLibInfos();
537  GetCanvas()->Refresh();
538 
539  return cmp_changed;
540 }
541 
542 
544 {
545  if( m_symbolList == NULL )
546  return false;
547 
548  wxArrayString aliasNames;
549 
550  try
551  {
552  Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
554  }
555  catch( const IO_ERROR& ) {} // ignore, it is handled below
556 
557  m_symbolList->Clear();
558 
559  if( aliasNames.IsEmpty() )
560  {
561  m_libraryName = wxEmptyString;
562  m_entryName = wxEmptyString;
563  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
564  m_unit = 1;
565  return true;
566  }
567 
568  m_symbolList->Append( aliasNames );
569 
570  int index = m_symbolList->FindString( m_entryName );
571  bool changed = false;
572 
573  if( index == wxNOT_FOUND )
574  {
575  // Select the first library entry when the previous entry name does not exist in
576  // the current library.
577  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
578  m_unit = 1;
579  index = 0;
580  changed = true;
581  m_entryName = wxEmptyString;
582  }
583 
584  m_symbolList->SetSelection( index, true );
585 
586  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
587  ProcessEvent( evt );
588 
589  return changed;
590 }
591 
592 
593 void SYMBOL_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event )
594 {
595  int ii = m_libList->GetSelection();
596 
597  if( ii < 0 )
598  return;
599 
600  m_selection_changed = true;
601 
602  SetSelectedLibrary( m_libList->GetString( ii ) );
603 }
604 
605 
606 void SYMBOL_VIEWER_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
607 {
608  if( m_libraryName == aLibraryName )
609  return;
610 
611  m_libraryName = aLibraryName;
613  GetCanvas()->Refresh();
614  DisplayLibInfos();
615 
616  // Ensure the corresponding line in m_libList is selected
617  // (which is not necessary the case if SetSelectedLibrary is called
618  // by another caller than ClickOnLibList.
619  m_libList->SetStringSelection( m_libraryName, true );
620 
621  // The m_libList has now the focus, in order to be able to use arrow keys
622  // to navigate inside the list.
623  // the gal canvas must not steal the focus to allow navigation
624  GetCanvas()->SetStealsFocus( false );
625  m_libList->SetFocus();
626 }
627 
628 
629 void SYMBOL_VIEWER_FRAME::ClickOnCmpList( wxCommandEvent& event )
630 {
631  int ii = m_symbolList->GetSelection();
632 
633  if( ii < 0 )
634  return;
635 
636  m_selection_changed = true;
637 
638  SetSelectedSymbol( m_symbolList->GetString( ii ));
639 
640  // The m_symbolList has now the focus, in order to be able to use arrow keys
641  // to navigate inside the list.
642  // the gal canvas must not steal the focus to allow navigation
643  GetCanvas()->SetStealsFocus( false );
644  m_symbolList->SetFocus();
645 }
646 
647 
648 void SYMBOL_VIEWER_FRAME::SetSelectedSymbol( const wxString& aSymbolName )
649 {
650  if( m_entryName != aSymbolName )
651  {
652  m_entryName = aSymbolName;
653 
654  // Ensure the corresponding line in m_symbolList is selected
655  // (which is not necessarily the case if SetSelectedSymbol is called
656  // by another caller than ClickOnCmpList.
657  m_symbolList->SetStringSelection( aSymbolName, true );
658  DisplayLibInfos();
659 
660  if( m_selection_changed )
661  {
662  m_unit = 1;
663  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
664  m_selection_changed = false;
665  }
666 
669  }
670 }
671 
672 
673 void SYMBOL_VIEWER_FRAME::DClickOnCmpList( wxCommandEvent& event )
674 {
676 }
677 
678 
680 {
681  auto cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
682 
684 
685  // Grid shape, etc.
686  GetGalDisplayOptions().ReadWindowSettings( cfg->m_LibViewPanel.window );
687 
688  m_libListWidth = cfg->m_LibViewPanel.lib_list_width;
689  m_symbolListWidth = cfg->m_LibViewPanel.cmp_list_width;
690 
691  GetRenderSettings()->m_ShowPinsElectricalType = cfg->m_LibViewPanel.show_pin_electrical_type;
692 
693  // Set parameters to a reasonable value.
694  if( m_libListWidth > m_frameSize.x / 2 )
695  m_libListWidth = m_frameSize.x / 2;
696 
697  if( m_symbolListWidth > m_frameSize.x / 2 )
699 }
700 
701 
703 {
704  EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
705 
707 
708  if( m_libListWidth && m_libList )
709  m_libListWidth = m_libList->GetSize().x;
710 
711  m_symbolListWidth = m_symbolList->GetSize().x;
712 
716 }
717 
718 
720 {
721  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
722  wxASSERT( cfg );
723  return &cfg->m_LibViewPanel.window;
724 }
725 
726 
727 void SYMBOL_VIEWER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
728 {
729  SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
730 
732  GetCanvas()->GetGAL()->DrawGrid();
733 
734  if( aEnvVarsChanged )
735  ReCreateLibList();
736 }
737 
738 
739 void SYMBOL_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
740 {
741  if( event.GetActive() )
742  {
743  bool changed = m_libList ? ReCreateLibList() : false;
744 
745  if (changed)
746  m_selection_changed = true;
747 
749 
750  DisplayLibInfos();
751  }
752 
753  event.Skip(); // required under wxMAC
754 }
755 
756 
757 void SYMBOL_VIEWER_FRAME::CloseLibraryViewer( wxCommandEvent& event )
758 {
759  Close();
760 }
761 
762 
764 {
765  m_listPowerCmpOnly = false;
766  m_allowedLibs.Clear();
767 
768  if( aFilter )
769  {
770  m_allowedLibs = aFilter->GetAllowedLibList();
772  }
773 
774  ReCreateLibList();
775 }
776 
777 
778 const BOX2I SYMBOL_VIEWER_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
779 {
780  LIB_PART* part = GetSelectedSymbol();
781 
782  if( !part )
783  {
784  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
785  }
786  else
787  {
788  std::shared_ptr< LIB_PART > tmp;
789 
790  tmp = ( part->IsAlias() ) ? part->GetParent().lock() : part->SharedPtr();
791 
792  wxCHECK( tmp, BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ) );
793 
794  EDA_RECT bbox = tmp->GetUnitBoundingBox( m_unit, m_convert );
795  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
796  }
797 }
798 
799 
801 {
802  if( m_symbolList->GetSelection() >= 0 )
803  DismissModal( true, m_libraryName + ':' + m_symbolList->GetStringSelection() );
804  else
805  DismissModal( false );
806 
807  Close( true );
808 }
809 
810 
811 void SYMBOL_VIEWER_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
812 {
813  std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_SYMBOL::g_Mutex, std::defer_lock );
814 
815  // One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway.
816  if( !dialogLock.try_lock() )
817  return;
818 
819  // Container doing search-as-you-type.
820  SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
821  wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> adapter = SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs );
822 
823  const auto libNicknames = libs->GetLogicalLibs();
824  static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapter.get() )->AddLibraries( libNicknames, this );
825 
826  LIB_PART* current = GetSelectedSymbol();
827  LIB_ID id;
828  int unit = 0;
829 
830  if( current )
831  {
832  id = current->GetLibId();
833  adapter->SetPreselectNode( id, unit );
834  }
835 
836  wxString dialogTitle;
837  dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
838 
839  DIALOG_CHOOSE_SYMBOL dlg( this, dialogTitle, adapter, m_convert, false, false, false );
840 
841  if( dlg.ShowQuasiModal() == wxID_CANCEL )
842  return;
843 
844  id = dlg.GetSelectedLibId( &unit );
845 
846  if( !id.IsValid() )
847  return;
848 
849  SetSelectedLibrary( id.GetLibNickname() );
850  SetSelectedSymbol( id.GetLibItemName() );
851  SetUnitAndConvert( unit, 1 );
852 }
853 
854 
855 void SYMBOL_VIEWER_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
856 {
857  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
858  int ii = m_symbolList->GetSelection();
859 
860  // Select the next symbol or stop at the end of the list.
861  if( ii != wxNOT_FOUND || ii != (int) m_symbolList->GetCount() - 1 )
862  ii += 1;
863 
864  m_symbolList->SetSelection( ii );
865  ProcessEvent( evt );
866 }
867 
868 
869 void SYMBOL_VIEWER_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
870 {
871  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
872  int ii = m_symbolList->GetSelection();
873 
874  // Select the previous symbol or stop at the beginning of list.
875  if( ii != wxNOT_FOUND && ii != 0 )
876  ii -= 1;
877 
878  m_symbolList->SetSelection( ii );
879  ProcessEvent( evt );
880 }
881 
882 
883 void SYMBOL_VIEWER_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
884 {
885  int ii = m_unitChoice->GetSelection();
886 
887  if( ii < 0 )
888  return;
889 
890  m_unit = ii + 1;
891 
893 }
894 
895 
897 {
898  if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
899  {
900  const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName, true );
901 
902  wxString title = wxString::Format( wxT( "%s \u2014 " ) + _( "Symbol Library Browser" ),
903  row ? row->GetFullURI() : _( "no library selected" ) );
904  SetTitle( title );
905  }
906 }
907 
908 
910 {
911  return m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
912 }
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.
static TOOL_ACTION showDatasheet
Inspection and Editing.
Definition: ee_actions.h:137
BOX2< VECTOR2I > BOX2I
Definition: box2.h:522
const UTF8 & GetLibItemName() const
Definition: lib_id.h:106
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.
LIB_ID GetLibId() const override
Definition: lib_symbol.h:131
LIB_FIELD & GetDatasheetField()
Return reference to the datasheet field.
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
wxString GetName() const override
Definition: lib_symbol.h:129
This file is part of the common library.
bool IsDismissed()
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
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)
PART_SPTR SharedPtr() const
Definition: lib_symbol.h:103
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:352
int GetWidth() const
Definition: eda_rect.h:114
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:99
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
void SetSize(const Vec &size)
Definition: box2.h:212
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.
wxString GetKeyWords() const
Definition: lib_symbol.h:151
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:168
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
void onUpdateUnitChoice(wxUpdateUIEvent &aEvent)
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:125
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)
Master controller class:
Definition: tool_manager.h:52
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.
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.
#define NULL
int GetUnitCount() const override
For items with units, return the number of units.
static TOOL_ACTION toggleGrid
Definition: actions.h:143
bool m_Center
Center on screen.
Definition: base_screen.h:100
void SyncView()
Mark all items for refresh.
EDA_MSG_PANEL * m_messagePanel
const wxPoint GetOrigin() const
Definition: eda_rect.h:106
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.
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.
PART_REF & GetParent()
Definition: lib_symbol.h:120
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:158
virtual void DrawGrid()
void SetSelectedSymbol(const wxString &aSymbolName)
Set the selected symbol.
Define a library symbol object.
Definition: lib_symbol.h:93
Helper dialog and control classes.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
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:92
bool ReCreateLibList()
Create o recreates a sorted list of currently loaded libraries.
wxString GetDescription() override
Definition: lib_symbol.h:138
static TOOL_ACTION addSymbolToSchematic
Definition: ee_actions.h:164
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:104
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.
bool GetFilterPowerParts() const
Specialization of the wxAuiPaneInfo class for KiCad panels.
#define DEFAULT_LINE_THICKNESS
The default wire width in mils. (can be changed in preference menu)
static TOOL_ACTION showDeMorganStandard
Definition: ee_actions.h:124
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:170
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:200
int GetHeight() const
Definition: eda_rect.h:115
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:159
Gather all the actions that are shared by tools.
Definition: ee_actions.h:39
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:171
PANEL_LIB_VIEW m_LibViewPanel
LIB_PART * GetSelectedSymbol() const
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:93
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:122
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:157
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)
#define _(s)
Definition: 3d_actions.cpp:33
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 ...
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
bool IsAlias() const
Definition: lib_symbol.h:168
void SetOrigin(const Vec &pos)
Definition: box2.h:210
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:197
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:322
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
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
Definition for part library class.
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.
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.
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.