KiCad PCB EDA Suite
viewlib_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-2018 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 
30 #include <fctsys.h>
31 #include <kiface_i.h>
32 #include <pgm_base.h>
33 #include <sch_draw_panel.h>
34 #include <sch_view.h>
35 #include <msgpanel.h>
36 #include <bitmaps.h>
37 #include <eda_dockart.h>
38 #include <sch_edit_frame.h>
39 #include <eeschema_id.h>
40 #include <general.h>
41 #include <viewlib_frame.h>
42 #include <symbol_lib_table.h>
43 #include <sch_legacy_plugin.h>
44 #include <hotkeys.h>
45 #include <dialog_helpers.h>
46 #include <class_libentry.h>
47 #include <class_library.h>
48 #include <view/view_controls.h>
49 #include <sch_painter.h>
50 
51 
52 // Save previous component library viewer state.
55 
58 
59 
60 BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME )
61  // Window events
62  EVT_CLOSE( LIB_VIEW_FRAME::OnCloseWindow )
63  EVT_SIZE( LIB_VIEW_FRAME::OnSize )
64  EVT_ACTIVATE( LIB_VIEW_FRAME::OnActivate )
65 
66  // Toolbar events
68  EVT_TOOL( ID_LIBVIEW_NEXT, LIB_VIEW_FRAME::onSelectNextSymbol )
69  EVT_TOOL( ID_LIBVIEW_PREVIOUS, LIB_VIEW_FRAME::onSelectPreviousSymbol )
70  EVT_TOOL( ID_LIBVIEW_VIEWDOC, LIB_VIEW_FRAME::onViewSymbolDocument )
72  LIB_VIEW_FRAME::onSelectSymbolBodyStyle )
73  EVT_TOOL( ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC, LIB_VIEW_FRAME::ExportToSchematicLibraryPart )
74  EVT_CHOICE( ID_LIBVIEW_SELECT_PART_NUMBER, LIB_VIEW_FRAME::onSelectSymbolUnit )
75 
76  // listbox events
77  EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, LIB_VIEW_FRAME::ClickOnLibList )
78  EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, LIB_VIEW_FRAME::ClickOnCmpList )
79  EVT_LISTBOX_DCLICK( ID_LIBVIEW_CMP_LIST, LIB_VIEW_FRAME::DClickOnCmpList )
80 
81  // Menu (and/or hotkey) events
82  EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
83  EVT_MENU( wxID_EXIT, LIB_VIEW_FRAME::CloseLibraryViewer )
84  EVT_MENU( ID_HELP_GET_INVOLVED, EDA_DRAW_FRAME::GetKicadContribute )
85  EVT_MENU( ID_SET_RELATIVE_OFFSET, LIB_VIEW_FRAME::OnSetRelativeOffset )
87 
88  EVT_UPDATE_UI( ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, LIB_VIEW_FRAME::onUpdateNormalBodyStyleButton )
89  EVT_UPDATE_UI( ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, LIB_VIEW_FRAME::onUpdateAltBodyStyleButton )
90  EVT_UPDATE_UI( ID_LIBVIEW_SHOW_ELECTRICAL_TYPE, LIB_VIEW_FRAME::OnUpdateElectricalType )
91  EVT_UPDATE_UI( ID_LIBVIEW_SELECT_PART_NUMBER, LIB_VIEW_FRAME::onUpdateUnitChoice )
92  EVT_UPDATE_UI( ID_LIBEDIT_VIEW_DOC, LIB_VIEW_FRAME::onUpdateDocButton )
93 
94 END_EVENT_TABLE()
95 
96 
97 #define LIB_VIEW_NAME "ViewlibFrame"
98 #define LIB_VIEW_NAME_MODAL "ViewlibFrameModal"
99 
100 #define LIB_VIEW_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
101 #define LIB_VIEW_STYLE_MODAL ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
102 
103 
104 LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
105  const wxString& aLibraryName ) :
106  SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Library Browser" ),
107  wxDefaultPosition, wxDefaultSize,
110  m_libList( nullptr ),
111  m_cmpList( nullptr ),
112  m_previewItem( nullptr )
113 {
114  wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL );
115 
116  if( aFrameType == FRAME_SCH_VIEWER_MODAL )
117  SetModal( true );
118 
119  // Force the frame name used in config. the lib viewer frame has a name
120  // depending on aFrameType (needed to identify the frame by wxWidgets),
121  // but only one configuration is preferable.
122  m_configFrameName = LIB_VIEW_NAME;
123 
124  // Give an icon
125  wxIcon icon;
126  icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) );
127  SetIcon( icon );
128 
129  m_hotkeysDescrList = g_Viewlib_Hokeys_Descr;
130  m_libListWidth = 200;
131  m_cmpListWidth = 300;
132  m_listPowerCmpOnly = false;
133  SetShowElectricalType( true );
134 
135  // Initialize grid id to the default value (50 mils):
137 
138  SetScreen( new SCH_SCREEN( aKiway ) );
139  GetScreen()->m_Center = true; // Axis origin centered on screen.
140  LoadSettings( config() );
141 
142  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
143 
144  SetPresetGrid( m_LastGridSizeId );
145 
146  // Menu bar is not mandatory: uncomment/comment the next line
147  // to add/remove the menubar
148  ReCreateMenuBar();
149  ReCreateHToolbar();
150  ReCreateVToolbar();
151 
152  m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
153  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
154 
155  m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxDefaultPosition, wxDefaultSize,
156  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
157 
158  if( aLibraryName.empty() )
159  {
160  ReCreateListLib();
161  }
162  else
163  {
164  m_libraryName = aLibraryName;
165  m_entryName.Clear();
166  m_unit = 1;
167  m_convert = 1;
168  }
169 
170  m_selection_changed = false;
171 
172  DisplayLibInfos();
173 
174  m_auimgr.SetManagedWindow( this );
175  m_auimgr.SetArtProvider( new EDA_DOCKART( this ) );
176 
177  // Manage main toolbar
178  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
179  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
180 
181  m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3)
182  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) );
183  m_auimgr.AddPane( m_cmpList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
184  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_cmpListWidth, -1 ) );
185 
186  m_auimgr.AddPane( m_canvas->GetWindow(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
187 
188  m_auimgr.GetPane( m_libList ).Show( aLibraryName.empty() );
189 
190  m_auimgr.Update();
191 
192  // Now Drawpanel is sized, we can use BestZoom to show the component (if any)
193 #ifdef USE_WX_GRAPHICS_CONTEXT
194  GetScreen()->SetScalingFactor( BestZoom() );
195 #else
196  Zoom_Automatique( false );
197 #endif
198 
199  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
200  {
201  Raise();
202  Show( true );
203  }
204 
205  SyncView();
206  GetGalCanvas()->GetViewControls()->SetSnapping( true );
207  GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
208  GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
209 }
210 
211 
213 {
214  if( m_previewItem )
216 }
217 
218 
219 void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
220 {
221  m_unit = aUnit > 0 ? aUnit : 1;
222  m_convert = aConvert > 0 ? aConvert : 1;
223  m_selection_changed = false;
224 
225  // Update canvas
228  GetCanvas()->GetView()->MarkDirty();
229  GetCanvas()->Refresh();
230 }
231 
232 
234 {
235  LIB_ALIAS* alias = NULL;
236 
237  if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
238  {
239  alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
240  }
241 
242  return alias;
243 }
244 
245 
247 {
248  LIB_PART* symbol = NULL;
249  LIB_ALIAS* alias = getSelectedAlias();
250 
251  if( alias )
252  symbol = alias->GetPart();
253 
254  return symbol;
255 }
256 
257 
259 {
260  LIB_ALIAS* alias = getSelectedAlias();
261  KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
262 
263  if( m_previewItem )
264  {
265  view->Remove( m_previewItem );
266  m_previewItem = nullptr;
267  }
268 
269  ClearMsgPanel();
270 
271  if( alias )
272  {
275 
276  view->Add( alias );
277  m_previewItem = alias;
278 
279  AppendMsgPanel( _( "Name" ), alias->GetName(), BLUE, 6 );
280  AppendMsgPanel( _( "Description" ), alias->GetDescription(), CYAN, 6 );
281  AppendMsgPanel( _( "Key words" ), alias->GetKeyWords(), DARKDARKGRAY );
282  }
283 
284  GetCanvas()->ForceRefresh();
285 }
286 
287 
288 void LIB_VIEW_FRAME::onUpdateAltBodyStyleButton( wxUpdateUIEvent& aEvent )
289 {
290  LIB_PART* symbol = getSelectedSymbol();
291 
292  aEvent.Enable( symbol && symbol->HasConversion() );
293 
294  if( symbol )
295  aEvent.Check( m_convert > 1 );
296  else
297  aEvent.Check( false );
298 }
299 
300 
301 void LIB_VIEW_FRAME::onUpdateNormalBodyStyleButton( wxUpdateUIEvent& aEvent )
302 {
303  LIB_PART* symbol = getSelectedSymbol();
304 
305  aEvent.Enable( symbol && symbol->HasConversion() );
306 
307  if( symbol )
308  aEvent.Check( m_convert <= 1 );
309  else
310  aEvent.Check( true );
311 }
312 
313 
314 void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
315 {
316  GetCanvas()->StopDrawing();
317 
318  if( !IsModal() )
319  {
320  Destroy();
321  }
322  else if( !IsDismissed() )
323  {
324  // only dismiss modal frame if not already dismissed.
325  DismissModal( false );
326 
327  // Modal frame will be destroyed by the calling function.
328  }
329 }
330 
331 
332 void LIB_VIEW_FRAME::OnSize( wxSizeEvent& SizeEv )
333 {
334  if( m_auimgr.GetManagedWindow() )
335  m_auimgr.Update();
336 
337  SizeEv.Skip();
338 }
339 
340 
341 void LIB_VIEW_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
342 {
344  UpdateStatusBar();
345 }
346 
347 
348 void LIB_VIEW_FRAME::OnShowElectricalType( wxCommandEvent& event )
349 {
351 
352  // Update canvas
354  GetCanvas()->GetView()->MarkDirty();
355  GetCanvas()->Refresh();
356 }
357 
358 
359 void LIB_VIEW_FRAME::OnUpdateElectricalType( wxUpdateUIEvent& aEvent )
360 {
361  aEvent.Check( GetShowElectricalType() );
362 }
363 
364 
365 void LIB_VIEW_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
366 {
367  LIB_PART* part = getSelectedSymbol();
368 
369  int unit_count = 1;
370 
371  if( part )
372  unit_count = std::max( part->GetUnitCount(), 1 );
373 
374  m_unitChoice->Enable( unit_count > 1 );
375 
376  if( unit_count > 1 )
377  {
378  // rebuild the unit list if it is not suitable (after a new selection for instance)
379  if( unit_count != (int)m_unitChoice->GetCount() )
380  {
381  m_unitChoice->Clear();
382 
383  for( int ii = 0; ii < unit_count; ii++ )
384  m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
385 
386  }
387 
388  if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
389  m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
390  }
391  else if( m_unitChoice->GetCount() )
392  m_unitChoice->Clear();
393 }
394 
395 
397 {
398  LIB_PART* part = NULL;
399  double defaultLibraryZoom = 7.33;
400 
401  if( m_libraryName.IsEmpty() || m_entryName.IsEmpty() )
402  {
403  SetScrollCenterPosition( wxPoint( 0, 0 ) );
404  return defaultLibraryZoom;
405  }
406 
407  LIB_ALIAS* alias = nullptr;
408 
409  try
410  {
411  alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
412  }
413  catch( ... )
414  {
415  }
416 
417  if( alias )
418  part = alias->GetPart();
419 
420  if( !part )
421  {
422  SetScrollCenterPosition( wxPoint( 0, 0 ) );
423  return defaultLibraryZoom;
424  }
425 
427 
428  double sizeX = (double) boundingBox.GetWidth();
429  double sizeY = (double) boundingBox.GetHeight();
430  wxPoint centre = boundingBox.Centre();
431 
432  // Reserve a 20% margin around component bounding box.
433  double margin_scale_factor = 1.2;
434 
435  return bestZoom( sizeX, sizeY, margin_scale_factor, centre );
436 }
437 
438 
440 {
441  if( !m_libList )
442  return false;
443 
444  m_libList->Clear();
445 
446  std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
447 
448  // Remove not allowed libs from main list, if the allowed lib list is not empty
449  if( m_allowedLibs.GetCount() )
450  {
451  for( unsigned ii = 0; ii < libs.size(); )
452  {
453  if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
454  libs.erase( libs.begin() + ii );
455  else
456  ii++;
457  }
458  }
459 
460  // Remove libs which have no power components, if this filter is activated
461  if( m_listPowerCmpOnly )
462  {
463  for( unsigned ii = 0; ii < libs.size(); )
464  {
465  wxArrayString aliasNames;
466 
467  Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
468 
469  if( aliasNames.IsEmpty() )
470  libs.erase( libs.begin() + ii );
471  else
472  ii++;
473  }
474  }
475 
476  if( libs.empty() )
477  return true;
478 
479  wxArrayString libNames;
480 
481  for( const auto& name : libs )
482  libNames.Add( name );
483 
484  m_libList->Append( libNames );
485 
486  // Search for a previous selection:
487  int index = m_libList->FindString( m_libraryName );
488 
489  if( index != wxNOT_FOUND )
490  {
491  m_libList->SetSelection( index, true );
492  }
493  else
494  {
495  // If not found, clear current library selection because it can be
496  // deleted after a config change.
497  m_libraryName = libs[0];
498  m_entryName = wxEmptyString;
499  m_unit = 1;
500  m_convert = 1;
501  }
502 
503  bool cmp_changed = ReCreateListCmp();
504  DisplayLibInfos();
505  m_canvas->Refresh();
506 
507  return cmp_changed;
508 }
509 
510 
512 {
513  if( m_cmpList == NULL )
514  return false;
515 
516  wxArrayString aliasNames;
517 
518  try
519  {
520  Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
522  }
523  catch( const IO_ERROR& ) {} // ignore, it is handled below
524 
525  m_cmpList->Clear();
526 
527  if( aliasNames.IsEmpty() )
528  {
529  m_libraryName = wxEmptyString;
530  m_entryName = wxEmptyString;
531  m_convert = 1;
532  m_unit = 1;
533  return true;
534  }
535 
536  m_cmpList->Append( aliasNames );
537 
538  int index = m_cmpList->FindString( m_entryName );
539  bool changed = false;
540 
541  if( index == wxNOT_FOUND )
542  {
543  // Select the first library entry when the previous entry name does not exist in
544  // the current library.
545  m_convert = 1;
546  m_unit = 1;
547  index = 0;
548  changed = true;
549  m_entryName = wxEmptyString;
550  }
551 
552  m_cmpList->SetSelection( index, true );
553 
554  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
555  ProcessEvent( evt );
556 
557  return changed;
558 }
559 
560 
561 void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
562 {
563  int ii = m_libList->GetSelection();
564 
565  if( ii < 0 )
566  return;
567 
568  m_selection_changed = true;
569 
570  SetSelectedLibrary( m_libList->GetString( ii ) );
571 }
572 
573 
574 void LIB_VIEW_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
575 {
576  if( m_libraryName == aLibraryName )
577  return;
578 
579  m_libraryName = aLibraryName;
580  ReCreateListCmp();
581  m_canvas->Refresh();
582  DisplayLibInfos();
583 
584  // Ensure the corresponding line in m_libList is selected
585  // (which is not necessary the case if SetSelectedLibrary is called
586  // by another caller than ClickOnLibList.
587  m_libList->SetStringSelection( m_libraryName, true );
588 }
589 
590 
591 void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
592 {
593  int ii = m_cmpList->GetSelection();
594 
595  if( ii < 0 )
596  return;
597 
598  m_selection_changed = true;
599 
600  SetSelectedComponent( m_cmpList->GetString( ii ) );
601 }
602 
603 
604 void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName )
605 {
606  if( m_entryName != aComponentName )
607  {
608  m_entryName = aComponentName;
609 
610  // Ensure the corresponding line in m_cmpList is selected
611  // (which is not necessarily the case if SetSelectedComponent is called
612  // by another caller than ClickOnCmpList.
613  m_cmpList->SetStringSelection( aComponentName, true );
614  DisplayLibInfos();
615 
616  if( m_selection_changed )
617  {
618  m_unit = 1;
619  m_convert = 1;
620  m_selection_changed = false;
621  }
622 
624  Zoom_Automatique( false );
625  }
626 }
627 
628 
629 void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
630 {
631  if( IsModal() )
632  {
634 
635  // The schematic editor might not be the parent of the library viewer.
636  // It could be a python window.
637  SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( GetParent() );
638 
639  if( schframe )
640  {
641  // Prevent the double click from being as a single click in the parent
642  // window which would cause the part to be parked rather than staying
643  // in drag mode.
644  schframe->SkipNextLeftButtonReleaseEvent();
645  }
646  }
647 }
648 
649 
650 void LIB_VIEW_FRAME::ExportToSchematicLibraryPart( wxCommandEvent& event )
651 {
652  int ii = m_cmpList->GetSelection();
653 
654  if( ii >= 0 )
655  {
656  wxString part_name = m_libraryName + ':' + m_cmpList->GetString( ii );
657 
658  // a selection was made, pass true
659  DismissModal( true, part_name );
660  }
661  else
662  {
663  // no selection was made, pass false
664  DismissModal( false );
665  }
666 
667  Close( true );
668 }
669 
670 
671 #define LIBLIST_WIDTH_KEY "ViewLiblistWidth"
672 #define CMPLIST_WIDTH_KEY "ViewCmplistWidth"
673 #define CMPVIEW_SHOW_PINELECTRICALTYPE_KEY "ViewCmpShowPinElectricalType"
674 
675 
676 void LIB_VIEW_FRAME::LoadSettings( wxConfigBase* aCfg )
677 {
679 
680  aCfg->Read( LIBLIST_WIDTH_KEY, &m_libListWidth, 150 );
681  aCfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 150 );
682  aCfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 150 );
684 
685  // Set parameters to a reasonable value.
686  if( m_libListWidth > m_FrameSize.x/2 )
688 
689  if( m_cmpListWidth > m_FrameSize.x/2 )
691 }
692 
693 
694 void LIB_VIEW_FRAME::SaveSettings( wxConfigBase* aCfg )
695 {
697 
698  if( m_libListWidth && m_libList )
699  {
700  m_libListWidth = m_libList->GetSize().x;
701  aCfg->Write( LIBLIST_WIDTH_KEY, m_libListWidth );
702  }
703 
704  m_cmpListWidth = m_cmpList->GetSize().x;
705  aCfg->Write( CMPLIST_WIDTH_KEY, m_cmpListWidth );
706 
708 }
709 
710 
711 void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
712 {
714 
715  bool changed = m_libList ? ReCreateListLib() : false;
716 
717  if (changed)
718  m_selection_changed = true;
719 
721 
722  DisplayLibInfos();
723 }
724 
725 
726 void LIB_VIEW_FRAME::CloseLibraryViewer( wxCommandEvent& event )
727 {
728  Close();
729 }
730 
731 
733 {
734  m_listPowerCmpOnly = false;
735  m_allowedLibs.Clear();
736 
737  if( aFilter )
738  {
739  m_allowedLibs = aFilter->GetAllowedLibList();
741  }
742 
743  ReCreateListLib();
744 }
745 
747 {
748  LIB_ALIAS* alias = getSelectedAlias();
749  LIB_PART* part = alias ? alias->GetPart() : nullptr;
750 
751  if( !part )
752  {
753  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
754  }
755  else
756  {
757  EDA_RECT bbox = part->GetUnitBoundingBox( m_unit, m_convert );
758  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
759 
760  }
761 }
Definition: colors.h:57
static int m_unit
static int m_convert
void SetFilter(const SCHLIB_FILTER *aFilter)
Set a filter to display only libraries and/or components which match the filter.
static wxString m_entryName
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
const EDA_RECT GetUnitBoundingBox(int aUnit, int aConvert) const
Get the bounding box for the symbol.
Part library alias object definition.
virtual void Zoom_Automatique(bool aWarpPointer) override
Redraw the screen with best zoom level and the best centering that shows all the page or the board...
FOOTPRINT_EDIT_FRAME::OnVerticalToolbar FOOTPRINT_EDIT_FRAME::ProcessPreferences FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions EVT_UPDATE_UI(ID_MODEDIT_LOAD_MODULE_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard) EVT_UPDATE_UI(ID_MODEDIT_INSERT_MODULE_IN_BOARD
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
bool GetShowElectricalType() const
void SetUnitAndConvert(int aUnit, int aConvert)
Set unit and convert, and set flag preventing them from automatically resetting to 1...
bool m_selection_changed
Updated to true if a list rewrite on GUI activation resulted in the component selection changing...
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
bool IsDismissed()
Function IsDismissed returns false only if both the frame is acting in modal mode and it has not been...
virtual void OnActivate(wxActivateEvent &event) override
Called when the frame is activated to reload the libraries and component lists that can be changed by...
double bestZoom(double sizeX, double sizeY, double scaleFactor, wxPoint centre)
EVT_TOOL_RANGE(ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, LIB_VIEW_FRAME::onSelectSymbolBodyStyle) LIB_VIEW_FRAME
VIEW_CONTROLS class definition.
LIB_ALIAS * m_previewItem
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
void SetScrollCenterPosition(const wxPoint &aPoint)
void OnCloseWindow(wxCloseEvent &Event)
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:365
int GetHeight() const
Definition: eda_rect.h:118
wxListBox * m_cmpList
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
wxArrayString m_allowedLibs
Schematic editor (Eeschema) main window.
wxAuiManager m_auimgr
static wxString m_libraryName
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...
void SkipNextLeftButtonReleaseEvent()
After calling this function, if the left mouse button is down, the next left mouse button release eve...
#define LIBLIST_WIDTH_KEY
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
void SetSelectedComponent(const wxString &aComponentName)
Set the selected component.
Symbol library viewer main window.
Definition: viewlib_frame.h:44
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:59
void onUpdateAltBodyStyleButton(wxUpdateUIEvent &aEvent)
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
bool m_showPinElectricalTypeName
the option to show the pin electrical name in the component editor
LIB_VIEW_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aLibraryName=wxEmptyString)
Constructor.
const wxArrayString & GetAllowedLibList() const
const wxString & GetKeyWords() const
Class LIB_ITEM definition.
void onUpdateUnitChoice(wxUpdateUIEvent &aEvent)
SCH_DRAW_PANEL * GetCanvas() const override
void CloseLibraryViewer(wxCommandEvent &event)
Definition: colors.h:59
Define a library symbol object.
Helper dialog and control classes.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
bool GetFilterPowerParts() const
void OnSetRelativeOffset(wxCommandEvent &event)
EVT_TOOL(ID_FOOTPRINT_WIZARD_SELECT_WIZARD, FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard) EVT_TOOL(ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT
wxPoint Centre() const
Definition: eda_rect.h:60
bool IsModal()
Definition: kiway_player.h:226
KIGFX::SCH_VIEW * GetView() const
const BOX2I GetDocumentExtents() const override
bool ReCreateListCmp()
Create or recreate the list of components in the currently selected library.
Specialization of the wxAuiPaneInfo class for KiCad panels.
void ExportToSchematicLibraryPart(wxCommandEvent &event)
Function ExportToSchematicLibraryPart exports the current component to schematic and close the librar...
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
#define LIB_VIEW_NAME
void DisplayLibInfos()
Definition: viewlibs.cpp:176
EDA_PANE & Canvas()
Function Canvas Turn *this into an undecorated pane suitable for a drawing canvas.
FOOTPRINT_EDIT_FRAME::OnVerticalToolbar EVT_MENU(ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, FOOTPRINT_EDIT_FRAME::ProcessPreferences) EVT_MENU(ID_PCB_LIB_TABLE_EDIT
LIB_PART * GetPart() const
Get the shared LIB_PART.
int GetUnitCount() const
const wxString & GetDescription() override
void UpdateStatusBar() override
Update the status bar information.
void ClickOnLibList(wxCommandEvent &event)
#define LIB_VIEW_NAME_MODAL
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:123
#define CMPVIEW_SHOW_PINELECTRICALTYPE_KEY
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
void updatePreviewSymbol()
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
LIB_PART * getSelectedSymbol() const
see class PGM_BASE
const wxString & GetName() const override
void onUpdateNormalBodyStyleButton(wxUpdateUIEvent &aEvent)
const char * name
Definition: DXF_plotter.cpp:61
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
#define max(a, b)
Definition: auxiliary.h:86
#define LIB_VIEW_STYLE_MODAL
void OnUpdateElectricalType(wxUpdateUIEvent &aEvent)
struct EDA_HOTKEY_CONFIG g_Viewlib_Hokeys_Descr[]
wxListBox * m_libList
LIB_ALIAS * getSelectedAlias() const
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
#define LIB_VIEW_STYLE
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void ClickOnCmpList(wxCommandEvent &event)
int GetWidth() const
Definition: eda_rect.h:117
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
wxChoice * m_unitChoice
double BestZoom() override
Return the zoom level which displays the full page on screen.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:335
Definition for part library class.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
void OnShowElectricalType(wxCommandEvent &event)
void DClickOnCmpList(wxCommandEvent &event)
Message panel definition file.
bool ReCreateListLib()
Creates or recreates a sorted list of currently loaded libraries.
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME, and SCH_EDIT_FRAME, and it brings in a common way of handling the provided virtual functions for the derived classes.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
virtual void OnActivate(wxActivateEvent &event)
Called when activating the frame.
void ClearMsgPanel(void)
Clear all messages from the message panel.
#define CMPLIST_WIDTH_KEY
bool ProcessEvent(wxEvent &aEvent) override
Function ProcessEvent overrides the default process event handler to implement the auto save feature...
void StopDrawing()
Function StopDrawing() Prevents the GAL canvas from further drawing till it is recreated or StartDraw...
void MarkDirty()
Function MarkDirty() Forces redraw of view on the next rendering.
Definition: view.h:621
void SetSelectedLibrary(const wxString &aLibName)
Set the selected library in the library window.
void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.