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  // Set the working/draw area size to display a symbol to a reasonable value:
211  // A 450mm x 450mm with a origin at the area center looks like a large working area
212  double max_size_x = Millimeter2iu( 450 );
213  double max_size_y = Millimeter2iu( 450 );
214  BOX2D bbox;
215  bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
216  bbox.SetSize( max_size_x, max_size_y );
217  GetCanvas()->GetView()->SetBoundary( bbox );
218 }
219 
220 
222 {
223  if( m_previewItem )
225 }
226 
227 
228 void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
229 {
230  m_unit = aUnit > 0 ? aUnit : 1;
231  m_convert = aConvert > 0 ? aConvert : 1;
232  m_selection_changed = false;
233 
234  // Update canvas
237  GetCanvas()->GetView()->MarkDirty();
238  GetCanvas()->Refresh();
239 }
240 
241 
243 {
244  LIB_ALIAS* alias = NULL;
245 
246  if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
247  {
248  alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
249  }
250 
251  return alias;
252 }
253 
254 
256 {
257  LIB_PART* symbol = NULL;
258  LIB_ALIAS* alias = getSelectedAlias();
259 
260  if( alias )
261  symbol = alias->GetPart();
262 
263  return symbol;
264 }
265 
266 
268 {
269  LIB_ALIAS* alias = getSelectedAlias();
270  KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
271 
272  if( m_previewItem )
273  {
274  view->Remove( m_previewItem );
275  m_previewItem = nullptr;
276  }
277 
278  ClearMsgPanel();
279 
280  if( alias )
281  {
284 
285  view->Add( alias );
286  m_previewItem = alias;
287 
288  AppendMsgPanel( _( "Name" ), alias->GetName(), BLUE, 6 );
289  AppendMsgPanel( _( "Description" ), alias->GetDescription(), CYAN, 6 );
290  AppendMsgPanel( _( "Key words" ), alias->GetKeyWords(), DARKDARKGRAY );
291  }
292 
293  GetCanvas()->ForceRefresh();
294 }
295 
296 
297 void LIB_VIEW_FRAME::onUpdateAltBodyStyleButton( wxUpdateUIEvent& aEvent )
298 {
299  LIB_PART* symbol = getSelectedSymbol();
300 
301  aEvent.Enable( symbol && symbol->HasConversion() );
302 
303  if( symbol )
304  aEvent.Check( m_convert > 1 );
305  else
306  aEvent.Check( false );
307 }
308 
309 
310 void LIB_VIEW_FRAME::onUpdateNormalBodyStyleButton( wxUpdateUIEvent& aEvent )
311 {
312  LIB_PART* symbol = getSelectedSymbol();
313 
314  aEvent.Enable( symbol && symbol->HasConversion() );
315 
316  if( symbol )
317  aEvent.Check( m_convert <= 1 );
318  else
319  aEvent.Check( true );
320 }
321 
322 
323 void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
324 {
325  GetCanvas()->StopDrawing();
326 
327  if( !IsModal() )
328  {
329  Destroy();
330  }
331  else if( !IsDismissed() )
332  {
333  // only dismiss modal frame if not already dismissed.
334  DismissModal( false );
335 
336  // Modal frame will be destroyed by the calling function.
337  }
338 }
339 
340 
341 void LIB_VIEW_FRAME::OnSize( wxSizeEvent& SizeEv )
342 {
343  if( m_auimgr.GetManagedWindow() )
344  m_auimgr.Update();
345 
346  SizeEv.Skip();
347 }
348 
349 
350 void LIB_VIEW_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
351 {
353  UpdateStatusBar();
354 }
355 
356 
357 void LIB_VIEW_FRAME::OnShowElectricalType( wxCommandEvent& event )
358 {
360 
361  // Update canvas
363  GetCanvas()->GetView()->MarkDirty();
364  GetCanvas()->Refresh();
365 }
366 
367 
368 void LIB_VIEW_FRAME::OnUpdateElectricalType( wxUpdateUIEvent& aEvent )
369 {
370  aEvent.Check( GetShowElectricalType() );
371 }
372 
373 
374 void LIB_VIEW_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
375 {
376  LIB_PART* part = getSelectedSymbol();
377 
378  int unit_count = 1;
379 
380  if( part )
381  unit_count = std::max( part->GetUnitCount(), 1 );
382 
383  m_unitChoice->Enable( unit_count > 1 );
384 
385  if( unit_count > 1 )
386  {
387  // rebuild the unit list if it is not suitable (after a new selection for instance)
388  if( unit_count != (int)m_unitChoice->GetCount() )
389  {
390  m_unitChoice->Clear();
391 
392  for( int ii = 0; ii < unit_count; ii++ )
393  m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
394 
395  }
396 
397  if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
398  m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
399  }
400  else if( m_unitChoice->GetCount() )
401  m_unitChoice->Clear();
402 }
403 
404 
406 {
407  LIB_PART* part = NULL;
408  double defaultLibraryZoom = 7.33;
409 
410  if( m_libraryName.IsEmpty() || m_entryName.IsEmpty() )
411  {
412  SetScrollCenterPosition( wxPoint( 0, 0 ) );
413  return defaultLibraryZoom;
414  }
415 
416  LIB_ALIAS* alias = nullptr;
417 
418  try
419  {
420  alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
421  }
422  catch( ... )
423  {
424  }
425 
426  if( alias )
427  part = alias->GetPart();
428 
429  if( !part )
430  {
431  SetScrollCenterPosition( wxPoint( 0, 0 ) );
432  return defaultLibraryZoom;
433  }
434 
436 
437  double sizeX = (double) boundingBox.GetWidth();
438  double sizeY = (double) boundingBox.GetHeight();
439  wxPoint centre = boundingBox.Centre();
440 
441  // Reserve a 20% margin around component bounding box.
442  double margin_scale_factor = 1.2;
443 
444  return bestZoom( sizeX, sizeY, margin_scale_factor, centre );
445 }
446 
447 
449 {
450  if( !m_libList )
451  return false;
452 
453  m_libList->Clear();
454 
455  std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
456 
457  // Remove not allowed libs from main list, if the allowed lib list is not empty
458  if( m_allowedLibs.GetCount() )
459  {
460  for( unsigned ii = 0; ii < libs.size(); )
461  {
462  if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
463  libs.erase( libs.begin() + ii );
464  else
465  ii++;
466  }
467  }
468 
469  // Remove libs which have no power components, if this filter is activated
470  if( m_listPowerCmpOnly )
471  {
472  for( unsigned ii = 0; ii < libs.size(); )
473  {
474  wxArrayString aliasNames;
475 
476  Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
477 
478  if( aliasNames.IsEmpty() )
479  libs.erase( libs.begin() + ii );
480  else
481  ii++;
482  }
483  }
484 
485  if( libs.empty() )
486  return true;
487 
488  wxArrayString libNames;
489 
490  for( const auto& name : libs )
491  libNames.Add( name );
492 
493  m_libList->Append( libNames );
494 
495  // Search for a previous selection:
496  int index = m_libList->FindString( m_libraryName );
497 
498  if( index != wxNOT_FOUND )
499  {
500  m_libList->SetSelection( index, true );
501  }
502  else
503  {
504  // If not found, clear current library selection because it can be
505  // deleted after a config change.
506  m_libraryName = libs[0];
507  m_entryName = wxEmptyString;
508  m_unit = 1;
509  m_convert = 1;
510  }
511 
512  bool cmp_changed = ReCreateListCmp();
513  DisplayLibInfos();
514  m_canvas->Refresh();
515 
516  return cmp_changed;
517 }
518 
519 
521 {
522  if( m_cmpList == NULL )
523  return false;
524 
525  wxArrayString aliasNames;
526 
527  try
528  {
529  Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
531  }
532  catch( const IO_ERROR& ) {} // ignore, it is handled below
533 
534  m_cmpList->Clear();
535 
536  if( aliasNames.IsEmpty() )
537  {
538  m_libraryName = wxEmptyString;
539  m_entryName = wxEmptyString;
540  m_convert = 1;
541  m_unit = 1;
542  return true;
543  }
544 
545  m_cmpList->Append( aliasNames );
546 
547  int index = m_cmpList->FindString( m_entryName );
548  bool changed = false;
549 
550  if( index == wxNOT_FOUND )
551  {
552  // Select the first library entry when the previous entry name does not exist in
553  // the current library.
554  m_convert = 1;
555  m_unit = 1;
556  index = 0;
557  changed = true;
558  m_entryName = wxEmptyString;
559  }
560 
561  m_cmpList->SetSelection( index, true );
562 
563  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
564  ProcessEvent( evt );
565 
566  return changed;
567 }
568 
569 
570 void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
571 {
572  int ii = m_libList->GetSelection();
573 
574  if( ii < 0 )
575  return;
576 
577  m_selection_changed = true;
578 
579  SetSelectedLibrary( m_libList->GetString( ii ) );
580 }
581 
582 
583 void LIB_VIEW_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
584 {
585  if( m_libraryName == aLibraryName )
586  return;
587 
588  m_libraryName = aLibraryName;
589  ReCreateListCmp();
590  m_canvas->Refresh();
591  DisplayLibInfos();
592 
593  // Ensure the corresponding line in m_libList is selected
594  // (which is not necessary the case if SetSelectedLibrary is called
595  // by another caller than ClickOnLibList.
596  m_libList->SetStringSelection( m_libraryName, true );
597 }
598 
599 
600 void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
601 {
602  int ii = m_cmpList->GetSelection();
603 
604  if( ii < 0 )
605  return;
606 
607  m_selection_changed = true;
608 
609  SetSelectedComponent( m_cmpList->GetString( ii ) );
610 }
611 
612 
613 void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName )
614 {
615  if( m_entryName != aComponentName )
616  {
617  m_entryName = aComponentName;
618 
619  // Ensure the corresponding line in m_cmpList is selected
620  // (which is not necessarily the case if SetSelectedComponent is called
621  // by another caller than ClickOnCmpList.
622  m_cmpList->SetStringSelection( aComponentName, true );
623  DisplayLibInfos();
624 
625  if( m_selection_changed )
626  {
627  m_unit = 1;
628  m_convert = 1;
629  m_selection_changed = false;
630  }
631 
633  Zoom_Automatique( false );
634  }
635 }
636 
637 
638 void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
639 {
640  if( IsModal() )
641  {
643 
644  // The schematic editor might not be the parent of the library viewer.
645  // It could be a python window.
646  SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( GetParent() );
647 
648  if( schframe )
649  {
650  // Prevent the double click from being as a single click in the parent
651  // window which would cause the part to be parked rather than staying
652  // in drag mode.
653  schframe->SkipNextLeftButtonReleaseEvent();
654  }
655  }
656 }
657 
658 
659 void LIB_VIEW_FRAME::ExportToSchematicLibraryPart( wxCommandEvent& event )
660 {
661  int ii = m_cmpList->GetSelection();
662 
663  if( ii >= 0 )
664  {
665  wxString part_name = m_libraryName + ':' + m_cmpList->GetString( ii );
666 
667  // a selection was made, pass true
668  DismissModal( true, part_name );
669  }
670  else
671  {
672  // no selection was made, pass false
673  DismissModal( false );
674  }
675 
676  Close( true );
677 }
678 
679 
680 #define LIBLIST_WIDTH_KEY "ViewLiblistWidth"
681 #define CMPLIST_WIDTH_KEY "ViewCmplistWidth"
682 #define CMPVIEW_SHOW_PINELECTRICALTYPE_KEY "ViewCmpShowPinElectricalType"
683 
684 
685 void LIB_VIEW_FRAME::LoadSettings( wxConfigBase* aCfg )
686 {
688 
689  // Fetch grid settings from Symbol Editor
690  wxString symbolEditor = LIB_EDIT_FRAME_NAME;
691  bool btmp;
692  COLOR4D wtmp;
693 
694  if( aCfg->Read( symbolEditor + ShowGridEntryKeyword, &btmp ) )
695  SetGridVisibility( btmp );
696 
697  if( wtmp.SetFromWxString( aCfg->Read( symbolEditor + GridColorEntryKeyword, wxT( "NONE" ) ) ) )
698  SetGridColor( wtmp );
699 
700  // Grid shape, etc.
701  GetGalDisplayOptions().ReadConfig( aCfg, symbolEditor + GAL_DISPLAY_OPTIONS_KEY );
702 
703  aCfg->Read( LIBLIST_WIDTH_KEY, &m_libListWidth, 150 );
704  aCfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 150 );
705  aCfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 150 );
707 
708  // Set parameters to a reasonable value.
709  if( m_libListWidth > m_FrameSize.x/2 )
711 
712  if( m_cmpListWidth > m_FrameSize.x/2 )
714 }
715 
716 
717 void LIB_VIEW_FRAME::SaveSettings( wxConfigBase* aCfg )
718 {
720 
721  if( m_libListWidth && m_libList )
722  {
723  m_libListWidth = m_libList->GetSize().x;
724  aCfg->Write( LIBLIST_WIDTH_KEY, m_libListWidth );
725  }
726 
727  m_cmpListWidth = m_cmpList->GetSize().x;
728  aCfg->Write( CMPLIST_WIDTH_KEY, m_cmpListWidth );
729 
731 }
732 
733 
734 void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
735 {
737 
738  bool changed = m_libList ? ReCreateListLib() : false;
739 
740  if (changed)
741  m_selection_changed = true;
742 
744 
745  DisplayLibInfos();
746 }
747 
748 
749 void LIB_VIEW_FRAME::CloseLibraryViewer( wxCommandEvent& event )
750 {
751  Close();
752 }
753 
754 
756 {
757  m_listPowerCmpOnly = false;
758  m_allowedLibs.Clear();
759 
760  if( aFilter )
761  {
762  m_allowedLibs = aFilter->GetAllowedLibList();
764  }
765 
766  ReCreateListLib();
767 }
768 
770 {
771  LIB_ALIAS* alias = getSelectedAlias();
772  LIB_PART* part = alias ? alias->GetPart() : nullptr;
773 
774  if( !part )
775  {
776  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
777  }
778  else
779  {
780  EDA_RECT bbox = part->GetUnitBoundingBox( m_unit, m_convert );
781  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
782 
783  }
784 }
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...
#define LIB_EDIT_FRAME_NAME
Definition: draw_frame.h:49
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).
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
Definition: draw_frame.h:943
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:375
int GetHeight() const
Definition: eda_rect.h:118
wxListBox * m_cmpList
void SetSize(const Vec &size)
Definition: box2.h:210
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...
virtual void SetGridColor(COLOR4D aColor)
Definition: draw_frame.h:550
#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
#define GAL_DISPLAY_OPTIONS_KEY
Definition: pgm_base.h:53
void ReadConfig(wxConfigBase *aCfg, const wxString &aBaseName)
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
static const wxString ShowGridEntryKeyword(wxT("ShowGrid"))
Nonzero to show grid (suffix)
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
void SetOrigin(const Vec &pos)
Definition: box2.h:208
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 SetGridVisibility(bool aVisible)
It may be overloaded by derived classes.
Definition: draw_frame.h:534
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:345
static const wxString GridColorEntryKeyword(wxT("GridColor"))
Grid color ID (suffix)
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.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39