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 #include <confirm.h>
51 
52 // Save previous component library viewer state.
55 
58 
59 
60 BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME )
61  // Window events
63  EVT_SIZE( LIB_VIEW_FRAME::OnSize )
64  EVT_ACTIVATE( LIB_VIEW_FRAME::OnActivate )
65 
66  // Toolbar events
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 )
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, _( "Symbol 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 bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
324 {
325  if( aSymbol && !aSymbol->IsEmpty() )
326  {
327  wxString msg;
328  LIB_TABLE* libTable = Prj().SchSymbolLibTable();
329  LIB_ID libid;
330 
331  libid.Parse( *aSymbol, LIB_ID::ID_SCH, true );
332 
333  if( libid.IsValid() )
334  {
335  wxString nickname = libid.GetLibNickname();
336 
337  if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
338  {
339  msg.sprintf( _( "The current configuration does not include a library with the\n"
340  "nickname \"%s\". Use Manage Symbol Libraries\n"
341  "to edit the configuration." ), nickname );
342  DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg );
343  }
344  else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
345  {
346  msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
347  "in the current configuration. Use Manage Symbol Libraries to\n"
348  "edit the configuration." ), nickname );
349  DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
350  }
351  else
352  {
355  }
356  }
357  }
358 
359  return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
360 }
361 
362 
363 void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
364 {
365  GetCanvas()->StopDrawing();
366 
367  if( !IsModal() )
368  {
369  Destroy();
370  }
371  else if( !IsDismissed() )
372  {
373  // only dismiss modal frame if not already dismissed.
374  DismissModal( false );
375 
376  // Modal frame will be destroyed by the calling function.
377  }
378 }
379 
380 
381 void LIB_VIEW_FRAME::OnSize( wxSizeEvent& SizeEv )
382 {
383  if( m_auimgr.GetManagedWindow() )
384  m_auimgr.Update();
385 
386  SizeEv.Skip();
387 }
388 
389 
390 void LIB_VIEW_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
391 {
393  UpdateStatusBar();
394 }
395 
396 
397 void LIB_VIEW_FRAME::OnShowElectricalType( wxCommandEvent& event )
398 {
400 
401  // Update canvas
403  GetCanvas()->GetView()->MarkDirty();
404  GetCanvas()->Refresh();
405 }
406 
407 
408 void LIB_VIEW_FRAME::OnUpdateElectricalType( wxUpdateUIEvent& aEvent )
409 {
410  aEvent.Check( GetShowElectricalType() );
411 }
412 
413 
414 void LIB_VIEW_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
415 {
416  LIB_PART* part = getSelectedSymbol();
417 
418  int unit_count = 1;
419 
420  if( part )
421  unit_count = std::max( part->GetUnitCount(), 1 );
422 
423  m_unitChoice->Enable( unit_count > 1 );
424 
425  if( unit_count > 1 )
426  {
427  // rebuild the unit list if it is not suitable (after a new selection for instance)
428  if( unit_count != (int)m_unitChoice->GetCount() )
429  {
430  m_unitChoice->Clear();
431 
432  for( int ii = 0; ii < unit_count; ii++ )
433  m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
434 
435  }
436 
437  if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
438  m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
439  }
440  else if( m_unitChoice->GetCount() )
441  m_unitChoice->Clear();
442 }
443 
444 
446 {
447  LIB_PART* part = NULL;
448  double defaultLibraryZoom = 7.33;
449 
450  if( m_libraryName.IsEmpty() || m_entryName.IsEmpty() )
451  {
452  SetScrollCenterPosition( wxPoint( 0, 0 ) );
453  return defaultLibraryZoom;
454  }
455 
456  LIB_ALIAS* alias = nullptr;
457 
458  try
459  {
460  alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
461  }
462  catch( ... )
463  {
464  }
465 
466  if( alias )
467  part = alias->GetPart();
468 
469  if( !part )
470  {
471  SetScrollCenterPosition( wxPoint( 0, 0 ) );
472  return defaultLibraryZoom;
473  }
474 
476 
477  double sizeX = (double) boundingBox.GetWidth();
478  double sizeY = (double) boundingBox.GetHeight();
479  wxPoint centre = boundingBox.Centre();
480 
481  // Reserve a 20% margin around component bounding box.
482  double margin_scale_factor = 1.2;
483 
484  return bestZoom( sizeX, sizeY, margin_scale_factor, centre );
485 }
486 
487 
489 {
490  if( !m_libList )
491  return false;
492 
493  m_libList->Clear();
494 
495  std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
496 
497  // Remove not allowed libs from main list, if the allowed lib list is not empty
498  if( m_allowedLibs.GetCount() )
499  {
500  for( unsigned ii = 0; ii < libs.size(); )
501  {
502  if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
503  libs.erase( libs.begin() + ii );
504  else
505  ii++;
506  }
507  }
508 
509  // Remove libs which have no power components, if this filter is activated
510  if( m_listPowerCmpOnly )
511  {
512  for( unsigned ii = 0; ii < libs.size(); )
513  {
514  wxArrayString aliasNames;
515 
516  Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
517 
518  if( aliasNames.IsEmpty() )
519  libs.erase( libs.begin() + ii );
520  else
521  ii++;
522  }
523  }
524 
525  if( libs.empty() )
526  return true;
527 
528  wxArrayString libNames;
529 
530  for( const auto& name : libs )
531  libNames.Add( name );
532 
533  m_libList->Append( libNames );
534 
535  // Search for a previous selection:
536  int index = m_libList->FindString( m_libraryName );
537 
538  if( index != wxNOT_FOUND )
539  {
540  m_libList->SetSelection( index, true );
541  }
542  else
543  {
544  // If not found, clear current library selection because it can be
545  // deleted after a config change.
546  m_libraryName = libs[0];
547  m_entryName = wxEmptyString;
548  m_unit = 1;
549  m_convert = 1;
550  }
551 
552  bool cmp_changed = ReCreateListCmp();
553  DisplayLibInfos();
554  m_canvas->Refresh();
555 
556  return cmp_changed;
557 }
558 
559 
561 {
562  if( m_cmpList == NULL )
563  return false;
564 
565  wxArrayString aliasNames;
566 
567  try
568  {
569  Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
571  }
572  catch( const IO_ERROR& ) {} // ignore, it is handled below
573 
574  m_cmpList->Clear();
575 
576  if( aliasNames.IsEmpty() )
577  {
578  m_libraryName = wxEmptyString;
579  m_entryName = wxEmptyString;
580  m_convert = 1;
581  m_unit = 1;
582  return true;
583  }
584 
585  m_cmpList->Append( aliasNames );
586 
587  int index = m_cmpList->FindString( m_entryName );
588  bool changed = false;
589 
590  if( index == wxNOT_FOUND )
591  {
592  // Select the first library entry when the previous entry name does not exist in
593  // the current library.
594  m_convert = 1;
595  m_unit = 1;
596  index = 0;
597  changed = true;
598  m_entryName = wxEmptyString;
599  }
600 
601  m_cmpList->SetSelection( index, true );
602 
603  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
604  ProcessEvent( evt );
605 
606  return changed;
607 }
608 
609 
610 void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
611 {
612  int ii = m_libList->GetSelection();
613 
614  if( ii < 0 )
615  return;
616 
617  m_selection_changed = true;
618 
619  SetSelectedLibrary( m_libList->GetString( ii ) );
620 }
621 
622 
623 void LIB_VIEW_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
624 {
625  if( m_libraryName == aLibraryName )
626  return;
627 
628  m_libraryName = aLibraryName;
629  ReCreateListCmp();
630  m_canvas->Refresh();
631  DisplayLibInfos();
632 
633  // Ensure the corresponding line in m_libList is selected
634  // (which is not necessary the case if SetSelectedLibrary is called
635  // by another caller than ClickOnLibList.
636  m_libList->SetStringSelection( m_libraryName, true );
637 }
638 
639 
640 void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
641 {
642  int ii = m_cmpList->GetSelection();
643 
644  if( ii < 0 )
645  return;
646 
647  m_selection_changed = true;
648 
649  SetSelectedComponent( m_cmpList->GetString( ii ) );
650 }
651 
652 
653 void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName )
654 {
655  if( m_entryName != aComponentName )
656  {
657  m_entryName = aComponentName;
658 
659  // Ensure the corresponding line in m_cmpList is selected
660  // (which is not necessarily the case if SetSelectedComponent is called
661  // by another caller than ClickOnCmpList.
662  m_cmpList->SetStringSelection( aComponentName, true );
663  DisplayLibInfos();
664 
665  if( m_selection_changed )
666  {
667  m_unit = 1;
668  m_convert = 1;
669  m_selection_changed = false;
670  }
671 
673  Zoom_Automatique( false );
674  }
675 }
676 
677 
678 void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
679 {
680  if( IsModal() )
681  {
683 
684  // The schematic editor might not be the parent of the library viewer.
685  // It could be a python window.
686  SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( GetParent() );
687 
688  if( schframe )
689  {
690  // Prevent the double click from being as a single click in the parent
691  // window which would cause the part to be parked rather than staying
692  // in drag mode.
693  schframe->SkipNextLeftButtonReleaseEvent();
694  }
695  }
696 }
697 
698 
699 void LIB_VIEW_FRAME::ExportToSchematicLibraryPart( wxCommandEvent& event )
700 {
701  int ii = m_cmpList->GetSelection();
702 
703  if( ii >= 0 )
704  {
705  wxString part_name = m_libraryName + ':' + m_cmpList->GetString( ii );
706 
707  // a selection was made, pass true
708  DismissModal( true, part_name );
709  }
710  else
711  {
712  // no selection was made, pass false
713  DismissModal( false );
714  }
715 
716  Close( true );
717 }
718 
719 
720 #define LIBLIST_WIDTH_KEY "ViewLiblistWidth"
721 #define CMPLIST_WIDTH_KEY "ViewCmplistWidth"
722 #define CMPVIEW_SHOW_PINELECTRICALTYPE_KEY "ViewCmpShowPinElectricalType"
723 
724 
725 void LIB_VIEW_FRAME::LoadSettings( wxConfigBase* aCfg )
726 {
728 
729  // Fetch grid settings from Symbol Editor
730  wxString symbolEditor = LIB_EDIT_FRAME_NAME;
731  bool btmp;
732  COLOR4D wtmp;
733 
734  if( aCfg->Read( symbolEditor + ShowGridEntryKeyword, &btmp ) )
735  SetGridVisibility( btmp );
736 
737  if( wtmp.SetFromWxString( aCfg->Read( symbolEditor + GridColorEntryKeyword, wxT( "NONE" ) ) ) )
738  SetGridColor( wtmp );
739 
740  // Grid shape, etc.
741  GetGalDisplayOptions().ReadConfig( aCfg, symbolEditor + GAL_DISPLAY_OPTIONS_KEY );
742 
743  aCfg->Read( LIBLIST_WIDTH_KEY, &m_libListWidth, 150 );
744  aCfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 150 );
746 
747  // Set parameters to a reasonable value.
748  if( m_libListWidth > m_FrameSize.x/2 )
750 
751  if( m_cmpListWidth > m_FrameSize.x/2 )
753 }
754 
755 
756 void LIB_VIEW_FRAME::SaveSettings( wxConfigBase* aCfg )
757 {
759 
760  if( m_libListWidth && m_libList )
761  {
762  m_libListWidth = m_libList->GetSize().x;
763  aCfg->Write( LIBLIST_WIDTH_KEY, m_libListWidth );
764  }
765 
766  m_cmpListWidth = m_cmpList->GetSize().x;
767  aCfg->Write( CMPLIST_WIDTH_KEY, m_cmpListWidth );
768 
770 }
771 
772 
773 void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
774 {
776 
777  bool changed = m_libList ? ReCreateListLib() : false;
778 
779  if (changed)
780  m_selection_changed = true;
781 
783 
784  DisplayLibInfos();
785 }
786 
787 
788 void LIB_VIEW_FRAME::CloseLibraryViewer( wxCommandEvent& event )
789 {
790  Close();
791 }
792 
793 
795 {
796  m_listPowerCmpOnly = false;
797  m_allowedLibs.Clear();
798 
799  if( aFilter )
800  {
801  m_allowedLibs = aFilter->GetAllowedLibList();
803  }
804 
805  ReCreateListLib();
806 }
807 
809 {
810  LIB_ALIAS* alias = getSelectedAlias();
811  LIB_PART* part = alias ? alias->GetPart() : nullptr;
812 
813  if( !part )
814  {
815  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
816  }
817  else
818  {
819  EDA_RECT bbox = part->GetUnitBoundingBox( m_unit, m_convert );
820  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
821 
822  }
823 }
Definition: colors.h:57
static int m_unit
static int m_convert
int GetUnitCount() const
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
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.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
#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.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
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,...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:257
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
Definition: draw_frame.h:953
bool ShowModal(wxString *aSymbol, wxWindow *aParent) override
Function ShowModal.
This file is part of the common library.
bool IsDismissed()
Function IsDismissed returns false only if both the frame is acting in modal mode and it has not been...
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
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 onSelectPreviousSymbol(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:104
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:376
int GetWidth() const
Definition: eda_rect.h:117
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:560
#define LIBLIST_WIDTH_KEY
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.
Definition: draw_frame.h:81
bool IsValid() const
Definition: lib_id.h:171
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)
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)
void OnSelectSymbol(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:45
void onViewSymbolDocument(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:126
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 wxPoint GetOrigin() const
Definition: eda_rect.h:112
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
Class LIB_ITEM definition.
void onUpdateUnitChoice(wxUpdateUIEvent &aEvent)
LIB_PART * getSelectedSymbol() const
coord_type GetWidth() const
Definition: box2.h:195
const wxString & GetKeyWords() const
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
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
void OnSetRelativeOffset(wxCommandEvent &event)
LIB_PART * GetPart() const
Get the shared LIB_PART.
EVT_TOOL(ID_FOOTPRINT_WIZARD_SELECT_WIZARD, FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard) EVT_TOOL(ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT
bool IsModal()
Definition: kiway_player.h:226
const BOX2I GetDocumentExtents() const override
bool ReCreateListCmp()
Create or recreate the list of components in the currently selected library.
bool GetFilterPowerParts() const
bool GetShowElectricalType() const
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.
int GetHeight() const
Definition: eda_rect.h:118
#define LIB_VIEW_NAME
void DisplayLibInfos()
Definition: viewlibs.cpp:183
KIGFX::SCH_VIEW * GetView() const
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
const wxString & GetDescription() override
void UpdateStatusBar() override
Update the status bar information.
void ClickOnLibList(wxCommandEvent &event)
void onSelectNextSymbol(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:90
#define LIB_VIEW_NAME_MODAL
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:126
#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.
see class PGM_BASE
const wxString & GetName() const override
void onUpdateNormalBodyStyleButton(wxUpdateUIEvent &aEvent)
Vec Centre() const
Definition: box2.h:77
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
#define ShowGridEntryKeyword
Nonzero to show grid (suffix)
Definition: draw_frame.h:65
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
const EDA_RECT GetUnitBoundingBox(int aUnit, int aConvert) const
Get the bounding box for the symbol.
#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)
const wxArrayString & GetAllowedLibList() const
coord_type GetHeight() const
Definition: box2.h:196
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:544
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
Definition for part library class.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
void OnShowElectricalType(wxCommandEvent &event)
void DClickOnCmpList(wxCommandEvent &event)
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
Message panel definition file.
bool ReCreateListLib()
Creates or recreates a sorted list of currently loaded libraries.
#define GridColorEntryKeyword
Grid color ID (suffix)
Definition: draw_frame.h:67
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
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.
VTBL_ENTRY bool ShowModal(wxString *aResult=NULL, wxWindow *aResultantFocusWindow=NULL)
Function ShowModal puts up this wxFrame as if it were a modal dialog, with all other instantiated wxF...
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
LIB_ALIAS * getSelectedAlias() const
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
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
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.