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-2019 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <fctsys.h>
27 #include <kiface_i.h>
28 #include <pgm_base.h>
29 #include <sch_draw_panel.h>
30 #include <sch_view.h>
31 #include <msgpanel.h>
32 #include <bitmaps.h>
33 #include <eda_dockart.h>
34 #include <sch_edit_frame.h>
35 #include <eeschema_id.h>
36 #include <general.h>
37 #include <viewlib_frame.h>
38 #include <symbol_lib_table.h>
39 #include <ee_hotkeys.h>
40 #include <dialog_helpers.h>
41 #include <class_libentry.h>
42 #include <class_library.h>
43 #include <view/view_controls.h>
44 #include <sch_painter.h>
45 #include <confirm.h>
46 #include <tool/tool_manager.h>
47 #include <tool/tool_dispatcher.h>
48 #include <tools/ee_actions.h>
49 #include <tool/common_tools.h>
50 #include <tool/zoom_tool.h>
51 #include <tools/lib_control.h>
52 
53 // Save previous component library viewer state.
56 
59 
60 
61 BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME )
62  // Window events
64  EVT_SIZE( LIB_VIEW_FRAME::OnSize )
65  EVT_ACTIVATE( LIB_VIEW_FRAME::OnActivate )
66 
67  // Toolbar events
73  LIB_VIEW_FRAME::onSelectSymbolBodyStyle )
74  EVT_CHOICE( ID_LIBVIEW_SELECT_PART_NUMBER, LIB_VIEW_FRAME::onSelectSymbolUnit )
75  EVT_TOOL( ID_ADD_PART_TO_SCHEMATIC, LIB_VIEW_FRAME::OnAddPartToSchematic )
76 
77  // listbox events
78  EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, LIB_VIEW_FRAME::ClickOnLibList )
79  EVT_LISTBOX( ID_LIBVIEW_CMP_LIST, LIB_VIEW_FRAME::ClickOnCmpList )
80  EVT_LISTBOX_DCLICK( ID_LIBVIEW_CMP_LIST, LIB_VIEW_FRAME::DClickOnCmpList )
81 
82  // Menu (and/or hotkey) events
83  EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
84  EVT_MENU( wxID_EXIT, LIB_VIEW_FRAME::CloseLibraryViewer )
85  EVT_MENU( ID_HELP_GET_INVOLVED, EDA_DRAW_FRAME::GetKicadContribute )
86  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 )
91  EVT_UPDATE_UI( ID_LIBEDIT_VIEW_DOC, LIB_VIEW_FRAME::onUpdateDocButton )
92 
93 END_EVENT_TABLE()
94 
95 
96 #define LIB_VIEW_NAME "ViewlibFrame"
97 #define LIB_VIEW_NAME_MODAL "ViewlibFrameModal"
98 
99 #define LIB_VIEW_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
100 #define LIB_VIEW_STYLE_MODAL ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
101 
102 
103 LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
104  const wxString& aLibraryName ) :
105  SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Symbol Library Browser" ),
106  wxDefaultPosition, wxDefaultSize,
109  m_libList( nullptr ),
110  m_cmpList( nullptr ),
111  m_previewItem( nullptr )
112 {
113  wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL );
114 
115  if( aFrameType == FRAME_SCH_VIEWER_MODAL )
116  SetModal( true );
117 
118  // Force the frame name used in config. the lib viewer frame has a name
119  // depending on aFrameType (needed to identify the frame by wxWidgets),
120  // but only one configuration is preferable.
121  m_configFrameName = LIB_VIEW_NAME;
122 
123  // Give an icon
124  wxIcon icon;
125  icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) );
126  SetIcon( icon );
127 
128  m_hotkeysDescrList = g_Viewlib_Hotkeys_Descr;
129  m_libListWidth = 200;
130  m_cmpListWidth = 300;
131  m_listPowerCmpOnly = false;
132  SetShowElectricalType( true );
133 
134  // Initialize grid id to the default value (50 mils):
136 
137  SetScreen( new SCH_SCREEN( aKiway ) );
138  GetScreen()->m_Center = true; // Axis origin centered on screen.
139  LoadSettings( config() );
140 
141  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
142 
143  setupTools();
144  ReCreateMenuBar();
145  ReCreateHToolbar();
146  ReCreateVToolbar();
147 
148  m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
149  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
150 
151  m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxDefaultPosition, wxDefaultSize,
152  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
153 
154  if( aLibraryName.empty() )
155  {
156  ReCreateListLib();
157  }
158  else
159  {
160  m_libraryName = aLibraryName;
161  m_entryName.Clear();
162  m_unit = 1;
163  m_convert = 1;
164  }
165 
166  m_selection_changed = false;
167 
168  DisplayLibInfos();
169 
170  m_auimgr.SetManagedWindow( this );
171  m_auimgr.SetArtProvider( new EDA_DOCKART( this ) );
172 
173  // Manage main toolbar
174  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
175  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
176 
177  m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3)
178  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) );
179  m_auimgr.AddPane( m_cmpList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
180  .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_cmpListWidth, -1 ) );
181 
182  m_auimgr.AddPane( m_canvas->GetWindow(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
183 
184  m_auimgr.GetPane( m_libList ).Show( aLibraryName.empty() );
185 
186  m_auimgr.Update();
187 
188  GetToolManager()->RunAction( "common.Control.gridPreset", true, m_LastGridSizeId );
189  GetToolManager()->RunAction( "common.Control.zoomFitScreen", true );
190 
191  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
192  {
193  Raise();
194  Show( true );
195  }
196 
197  SyncView();
198  GetGalCanvas()->GetViewControls()->SetSnapping( true );
199  GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
200  GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
201 
202  // Set the working/draw area size to display a symbol to a reasonable value:
203  // A 450mm x 450mm with a origin at the area center looks like a large working area
204  double max_size_x = Millimeter2iu( 450 );
205  double max_size_y = Millimeter2iu( 450 );
206  BOX2D bbox;
207  bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
208  bbox.SetSize( max_size_x, max_size_y );
209  GetCanvas()->GetView()->SetBoundary( bbox );
210 }
211 
212 
214 {
215  if( m_previewItem )
217 }
218 
219 
221 {
222  // Create the manager and dispatcher & route draw panel events to the dispatcher
225  GetCanvas()->GetViewControls(), this );
226  m_actions = new EE_ACTIONS();
228 
229  // Register tools
233 
235 
237 }
238 
239 
240 void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert )
241 {
242  m_unit = aUnit > 0 ? aUnit : 1;
243  m_convert = aConvert > 0 ? aConvert : LIB_ITEM::LIB_CONVERT::BASE;
244  m_selection_changed = false;
245 
246  // Update canvas
249  GetCanvas()->GetView()->MarkDirty();
250  GetCanvas()->Refresh();
251 }
252 
253 
255 {
256  LIB_ALIAS* alias = NULL;
257 
258  if( !m_libraryName.IsEmpty() && !m_entryName.IsEmpty() )
259  alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
260 
261  return alias;
262 }
263 
264 
266 {
267  LIB_PART* symbol = NULL;
268  LIB_ALIAS* alias = getSelectedAlias();
269 
270  if( alias )
271  symbol = alias->GetPart();
272 
273  return symbol;
274 }
275 
276 
278 {
279  LIB_ALIAS* alias = getSelectedAlias();
280  KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
281 
282  if( m_previewItem )
283  {
284  view->Remove( m_previewItem );
285  m_previewItem = nullptr;
286  }
287 
288  ClearMsgPanel();
289 
290  if( alias )
291  {
294 
295  view->Add( alias );
296  m_previewItem = alias;
297 
298  AppendMsgPanel( _( "Name" ), alias->GetName(), BLUE, 6 );
299  AppendMsgPanel( _( "Description" ), alias->GetDescription(), CYAN, 6 );
300  AppendMsgPanel( _( "Key words" ), alias->GetKeyWords(), DARKDARKGRAY );
301  }
302 
303  GetCanvas()->ForceRefresh();
304 }
305 
306 
307 void LIB_VIEW_FRAME::onUpdateAltBodyStyleButton( wxUpdateUIEvent& aEvent )
308 {
309  LIB_PART* symbol = getSelectedSymbol();
310 
311  aEvent.Enable( symbol && symbol->HasConversion() );
312 
313  if( symbol )
314  aEvent.Check( m_convert > 1 );
315  else
316  aEvent.Check( false );
317 }
318 
319 
320 void LIB_VIEW_FRAME::onUpdateNormalBodyStyleButton( wxUpdateUIEvent& aEvent )
321 {
322  LIB_PART* symbol = getSelectedSymbol();
323 
324  aEvent.Enable( symbol && symbol->HasConversion() );
325 
326  if( symbol )
327  aEvent.Check( m_convert <= 1 );
328  else
329  aEvent.Check( true );
330 }
331 
332 
333 bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
334 {
335  if( aSymbol && !aSymbol->IsEmpty() )
336  {
337  wxString msg;
338  LIB_TABLE* libTable = Prj().SchSymbolLibTable();
339  LIB_ID libid;
340 
341  libid.Parse( *aSymbol, LIB_ID::ID_SCH, true );
342 
343  if( libid.IsValid() )
344  {
345  wxString nickname = libid.GetLibNickname();
346 
347  if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
348  {
349  msg.sprintf( _( "The current configuration does not include a library with the\n"
350  "nickname \"%s\". Use Manage Symbol Libraries\n"
351  "to edit the configuration." ), nickname );
352  DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg );
353  }
354  else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
355  {
356  msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
357  "in the current configuration. Use Manage Symbol Libraries to\n"
358  "edit the configuration." ), nickname );
359  DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
360  }
361  else
362  {
365  }
366  }
367  }
368 
369  return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
370 }
371 
372 
373 void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
374 {
375  GetCanvas()->StopDrawing();
376 
377  if( !IsModal() )
378  {
379  Destroy();
380  }
381  else if( !IsDismissed() )
382  {
383  // only dismiss modal frame if not already dismissed.
384  DismissModal( false );
385 
386  // Modal frame will be destroyed by the calling function.
387  }
388 }
389 
390 
391 void LIB_VIEW_FRAME::OnSize( wxSizeEvent& SizeEv )
392 {
393  if( m_auimgr.GetManagedWindow() )
394  m_auimgr.Update();
395 
396  SizeEv.Skip();
397 }
398 
399 
400 void LIB_VIEW_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
401 {
403  UpdateStatusBar();
404 }
405 
406 
407 void LIB_VIEW_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
408 {
409  LIB_PART* part = getSelectedSymbol();
410 
411  int unit_count = 1;
412 
413  if( part )
414  unit_count = std::max( part->GetUnitCount(), 1 );
415 
416  m_unitChoice->Enable( unit_count > 1 );
417 
418  if( unit_count > 1 )
419  {
420  // rebuild the unit list if it is not suitable (after a new selection for instance)
421  if( unit_count != (int)m_unitChoice->GetCount() )
422  {
423  m_unitChoice->Clear();
424 
425  for( int ii = 0; ii < unit_count; ii++ )
426  m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) );
427 
428  }
429 
430  if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
431  m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
432  }
433  else if( m_unitChoice->GetCount() )
434  m_unitChoice->Clear();
435 }
436 
437 
439 {
440  LIB_PART* part = NULL;
441  double defaultLibraryZoom = 7.33;
442 
443  if( m_libraryName.IsEmpty() || m_entryName.IsEmpty() )
444  {
445  SetScrollCenterPosition( wxPoint( 0, 0 ) );
446  return defaultLibraryZoom;
447  }
448 
449  LIB_ALIAS* alias = nullptr;
450 
451  try
452  {
453  alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
454  }
455  catch( ... )
456  {
457  }
458 
459  if( alias )
460  part = alias->GetPart();
461 
462  if( !part )
463  {
464  SetScrollCenterPosition( wxPoint( 0, 0 ) );
465  return defaultLibraryZoom;
466  }
467 
469 
470  double sizeX = (double) boundingBox.GetWidth();
471  double sizeY = (double) boundingBox.GetHeight();
472  wxPoint centre = boundingBox.Centre();
473 
474  // Reserve a 20% margin around component bounding box.
475  double margin_scale_factor = 1.2;
476 
477  return bestZoom( sizeX, sizeY, margin_scale_factor, centre );
478 }
479 
480 
482 {
483  if( !m_libList )
484  return false;
485 
486  m_libList->Clear();
487 
488  std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
489 
490  // Remove not allowed libs from main list, if the allowed lib list is not empty
491  if( m_allowedLibs.GetCount() )
492  {
493  for( unsigned ii = 0; ii < libs.size(); )
494  {
495  if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND )
496  libs.erase( libs.begin() + ii );
497  else
498  ii++;
499  }
500  }
501 
502  // Remove libs which have no power components, if this filter is activated
503  if( m_listPowerCmpOnly )
504  {
505  for( unsigned ii = 0; ii < libs.size(); )
506  {
507  wxArrayString aliasNames;
508 
509  Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true );
510 
511  if( aliasNames.IsEmpty() )
512  libs.erase( libs.begin() + ii );
513  else
514  ii++;
515  }
516  }
517 
518  if( libs.empty() )
519  return true;
520 
521  wxArrayString libNames;
522 
523  for( const auto& name : libs )
524  libNames.Add( name );
525 
526  m_libList->Append( libNames );
527 
528  // Search for a previous selection:
529  int index = m_libList->FindString( m_libraryName );
530 
531  if( index != wxNOT_FOUND )
532  {
533  m_libList->SetSelection( index, true );
534  }
535  else
536  {
537  // If not found, clear current library selection because it can be
538  // deleted after a config change.
539  m_libraryName = libs[0];
540  m_entryName = wxEmptyString;
541  m_unit = 1;
542  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
543  }
544 
545  bool cmp_changed = ReCreateListCmp();
546  DisplayLibInfos();
547  m_canvas->Refresh();
548 
549  return cmp_changed;
550 }
551 
552 
554 {
555  if( m_cmpList == NULL )
556  return false;
557 
558  wxArrayString aliasNames;
559 
560  try
561  {
562  Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
564  }
565  catch( const IO_ERROR& ) {} // ignore, it is handled below
566 
567  m_cmpList->Clear();
568 
569  if( aliasNames.IsEmpty() )
570  {
571  m_libraryName = wxEmptyString;
572  m_entryName = wxEmptyString;
573  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
574  m_unit = 1;
575  return true;
576  }
577 
578  m_cmpList->Append( aliasNames );
579 
580  int index = m_cmpList->FindString( m_entryName );
581  bool changed = false;
582 
583  if( index == wxNOT_FOUND )
584  {
585  // Select the first library entry when the previous entry name does not exist in
586  // the current library.
587  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
588  m_unit = 1;
589  index = 0;
590  changed = true;
591  m_entryName = wxEmptyString;
592  }
593 
594  m_cmpList->SetSelection( index, true );
595 
596  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
597  ProcessEvent( evt );
598 
599  return changed;
600 }
601 
602 
603 void LIB_VIEW_FRAME::ClickOnLibList( wxCommandEvent& event )
604 {
605  int ii = m_libList->GetSelection();
606 
607  if( ii < 0 )
608  return;
609 
610  m_selection_changed = true;
611 
612  SetSelectedLibrary( m_libList->GetString( ii ) );
613 }
614 
615 
616 void LIB_VIEW_FRAME::SetSelectedLibrary( const wxString& aLibraryName )
617 {
618  if( m_libraryName == aLibraryName )
619  return;
620 
621  m_libraryName = aLibraryName;
622  ReCreateListCmp();
623  m_canvas->Refresh();
624  DisplayLibInfos();
625 
626  // Ensure the corresponding line in m_libList is selected
627  // (which is not necessary the case if SetSelectedLibrary is called
628  // by another caller than ClickOnLibList.
629  m_libList->SetStringSelection( m_libraryName, true );
630 }
631 
632 
633 void LIB_VIEW_FRAME::ClickOnCmpList( wxCommandEvent& event )
634 {
635  int ii = m_cmpList->GetSelection();
636 
637  if( ii < 0 )
638  return;
639 
640  m_selection_changed = true;
641 
642  SetSelectedComponent( m_cmpList->GetString( ii ) );
643 }
644 
645 
646 void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName )
647 {
648  if( m_entryName != aComponentName )
649  {
650  m_entryName = aComponentName;
651 
652  // Ensure the corresponding line in m_cmpList is selected
653  // (which is not necessarily the case if SetSelectedComponent is called
654  // by another caller than ClickOnCmpList.
655  m_cmpList->SetStringSelection( aComponentName, true );
656  DisplayLibInfos();
657 
658  if( m_selection_changed )
659  {
660  m_unit = 1;
661  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
662  m_selection_changed = false;
663  }
664 
666  m_toolManager->RunAction( "common.Control.zoomFitScreen", true );
667  }
668 }
669 
670 
671 void LIB_VIEW_FRAME::DClickOnCmpList( wxCommandEvent& event )
672 {
673  OnAddPartToSchematic( event );
674 
675  // The schematic editor might not be the parent of the library viewer.
676  // It could be a python window.
677  SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( GetParent() );
678 
679  if( schframe )
680  {
681  // Prevent the double click from being as a single click in the parent
682  // window which would cause the part to be parked rather than staying
683  // in drag mode.
684  schframe->SkipNextLeftButtonReleaseEvent();
685  }
686 }
687 
688 
689 #define LIBLIST_WIDTH_KEY "ViewLiblistWidth"
690 #define CMPLIST_WIDTH_KEY "ViewCmplistWidth"
691 #define CMPVIEW_SHOW_PINELECTRICALTYPE_KEY "ViewCmpShowPinElectricalType"
692 
693 
694 void LIB_VIEW_FRAME::LoadSettings( wxConfigBase* aCfg )
695 {
697 
698  // Fetch display settings from Symbol Editor as the Symbol Viewer
699  // doesn't have its own config
700  wxString symbolEditor = LIB_EDIT_FRAME_NAME;
701  bool btmp;
702  COLOR4D wtmp;
703 
704  if( aCfg->Read( symbolEditor + ShowGridEntryKeyword, &btmp ) )
705  SetGridVisibility( btmp );
706 
707  if( wtmp.SetFromWxString( aCfg->Read( symbolEditor + GridColorEntryKeyword, wxT( "NONE" ) ) ) )
708  SetGridColor( wtmp );
709 
710  // Grid shape, etc.
711  GetGalDisplayOptions().ReadAppConfig( *aCfg, symbolEditor );
712 
713  aCfg->Read( LIBLIST_WIDTH_KEY, &m_libListWidth, 150 );
714  aCfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 150 );
716 
717  // Set parameters to a reasonable value.
718  if( m_libListWidth > m_FrameSize.x/2 )
720 
721  if( m_cmpListWidth > m_FrameSize.x/2 )
723 }
724 
725 
726 void LIB_VIEW_FRAME::SaveSettings( wxConfigBase* aCfg )
727 {
729 
730  if( m_libListWidth && m_libList )
731  {
732  m_libListWidth = m_libList->GetSize().x;
733  aCfg->Write( LIBLIST_WIDTH_KEY, m_libListWidth );
734  }
735 
736  m_cmpListWidth = m_cmpList->GetSize().x;
737  aCfg->Write( CMPLIST_WIDTH_KEY, m_cmpListWidth );
738 
740 }
741 
742 
743 void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event )
744 {
746 
747  bool changed = m_libList ? ReCreateListLib() : false;
748 
749  if (changed)
750  m_selection_changed = true;
751 
753 
754  DisplayLibInfos();
755 }
756 
757 
758 void LIB_VIEW_FRAME::CloseLibraryViewer( wxCommandEvent& event )
759 {
760  Close();
761 }
762 
763 
765 {
766  m_listPowerCmpOnly = false;
767  m_allowedLibs.Clear();
768 
769  if( aFilter )
770  {
771  m_allowedLibs = aFilter->GetAllowedLibList();
773  }
774 
775  ReCreateListLib();
776 }
777 
778 
780 {
781  LIB_ALIAS* alias = getSelectedAlias();
782  LIB_PART* part = alias ? alias->GetPart() : nullptr;
783 
784  if( !part )
785  {
786  return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) );
787  }
788  else
789  {
790  EDA_RECT bbox = part->GetUnitBoundingBox( m_unit, m_convert );
791  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
792 
793  }
794 }
795 
796 
797 void LIB_VIEW_FRAME::OnAddPartToSchematic( wxCommandEvent& aEvent )
798 {
799  if( IsModal() )
800  {
801  // if we're modal then we just need to return the symbol selection; the caller is
802  // already in a EE_ACTIONS::placeSymbol coroutine.
803  if( m_cmpList->GetSelection() >= 0 )
804  DismissModal( true, m_libraryName + ':' + m_cmpList->GetStringSelection() );
805  else
806  DismissModal( false );
807 
808  Close( true );
809  return;
810  }
811 
812  if( getSelectedSymbol() )
813  {
814  SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );
815 
816  if( schframe == NULL ) // happens when the schematic editor is not active (or closed)
817  {
818  DisplayErrorMessage( this, _("No schematic currently open." ) );
819  return;
820  }
821 
822  SCH_COMPONENT* component = new SCH_COMPONENT( *getSelectedSymbol(),
823  getSelectedAlias()->GetLibId(),
825 
826  // Be sure the link to the corresponding LIB_PART is OK:
827  component->Resolve( *Prj().SchSymbolLibTable() );
828 
829  if( schframe->GetAutoplaceFields() )
830  component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
831 
832  schframe->Raise();
833  schframe->GetToolManager()->RunAction( EE_ACTIONS::placeSymbol, true, component );
834  }
835 }
836 
837 
838 bool LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
839 {
840  bool eventHandled = true;
841 
842  // Filter out the 'fake' mouse motion after a keyboard movement
843  if( !aHotKey && m_movingCursorWithKeyboard )
844  {
846  return false;
847  }
848 
849  wxPoint pos = aPosition;
850  GeneralControlKeyMovement( aHotKey, &pos, true );
851 
852  // Update cursor position.
853  m_canvas->CrossHairOn( aDC );
854  SetCrossHairPosition( pos, true );
855 
856  if( aHotKey )
857  {
858  SCH_SCREEN* screen = GetScreen();
859 
860  if( screen->GetCurItem() && screen->GetCurItem()->GetEditFlags() )
861  eventHandled = OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() );
862  else
863  eventHandled = OnHotKey( aDC, aHotKey, aPosition, NULL );
864  }
865 
866  UpdateStatusBar(); // Display cursor coordinates info.
867 
868  return eventHandled;
869 }
Definition: colors.h:57
static int m_unit
TOOL_MANAGER * m_toolManager
Definition: draw_frame.h:130
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.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
#define LIB_EDIT_FRAME_NAME
Definition: draw_frame.h:50
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:61
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.
struct EDA_HOTKEY_CONFIG g_Viewlib_Hotkeys_Descr[]
Definition: ee_hotkeys.cpp:416
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:258
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
Definition: draw_frame.h:949
bool ShowModal(wxString *aSymbol, wxWindow *aParent) override
Function ShowModal.
bool GeneralControl(wxDC *aDC, const wxPoint &aPosition, EDA_KEY aHotKey) override
Perform application specific control using aDC at aPosition in logical units.
This file is part of the common library.
TOOL_DISPATCHER * m_toolDispatcher
Definition: draw_frame.h:131
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:100
bool Resolve(PART_LIBS *aLibs)
Assigns the current LIB_PART from aLibs which this symbol is based on.
void SetScrollCenterPosition(const wxPoint &aPoint)
void OnCloseWindow(wxCloseEvent &Event)
EVT_TOOL(ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE, PCB_EDIT_FRAME::OnSelectOptionToolbar) EVT_TOOL_RANGE(ID_TB_OPTIONS_SHOW_ZONES
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
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, EDA_DRAW_FRAME *aFrame)
Sets the work environment (model, view, view controls and the parent window).
EDA_ITEM * GetCurItem() const
Definition: base_screen.h:233
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:558
#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:82
bool IsValid() const
Definition: lib_id.h:171
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
bool GetAutoplaceFields() const
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
void SaveSettings(wxConfigBase *aCfg) override
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:43
bool GeneralControlKeyMovement(int aHotKey, wxPoint *aPos, bool aSnapToGrid)
Handle the common part of GeneralControl dedicated to global cursor keys (i.e.
Class LIB_CONTROL.
Definition: lib_control.h:38
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:59
void onUpdateAltBodyStyleButton(wxUpdateUIEvent &aEvent)
Class TOOL_MANAGER.
Definition: tool_manager.h:49
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
void OnSelectSymbol(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:41
void onViewSymbolDocument(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:122
SCH_SHEET_PATH * g_CurrentSheet
With the new connectivity algorithm, many more places than before want to know what the current sheet...
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:321
LIB_VIEW_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aLibraryName=wxEmptyString)
Constructor.
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:263
virtual void CrossHairOn(wxDC *DC=nullptr)
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
TOOL_MANAGER * GetToolManager() const override
Return the tool manager instance, if any.
Definition: draw_frame.h:937
SCH_DRAW_PANEL * GetCanvas() const override
void OnAddPartToSchematic(wxCommandEvent &aEvent)
void CloseLibraryViewer(wxCommandEvent &event)
bool OnHotKey(wxDC *aDC, int aHotKey, const wxPoint &aPosition, EDA_ITEM *aItem) override
Handle hot key events.
Definition: ee_hotkeys.cpp:606
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
uint32_t EDA_KEY
Definition: common.h:71
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.
static TOOL_ACTION placeSymbol
Definition: ee_actions.h:78
bool IsModal()
Definition: kiway_player.h:233
virtual void ClearMsgPanel()
Clear all messages from the message panel.
bool m_showPinElectricalTypeName
const BOX2I GetDocumentExtents() const override
bool ReCreateListCmp()
Create or recreate the list of components in the currently selected library.
bool GetFilterPowerParts() const
Specialization of the wxAuiPaneInfo class for KiCad panels.
void ReadAppConfig(wxConfigBase &aCfg, const wxString &aBaseName)
Read GAL config options from applicaton-level config.
void LoadSettings(wxConfigBase *aCfg) override
Load common frame parameters from a configuration file.
int GetHeight() const
Definition: eda_rect.h:118
#define LIB_VIEW_NAME
void DisplayLibInfos()
Definition: viewlibs.cpp:170
Class EESCHEMA_ACTIONS.
Definition: ee_actions.h:42
Class COMMON_TOOLS.
Definition: common_tools.h:38
Class TOOL_DISPATCHER.
KIGFX::SCH_VIEW * GetView() const
EDA_PANE & 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:86
#define LIB_VIEW_NAME_MODAL
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:128
#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
Saves common frame parameters to a configuration data file.
see class PGM_BASE
const wxString & GetName() const override
void onUpdateNormalBodyStyleButton(wxUpdateUIEvent &aEvent)
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Automatically orient all the fields in the component.
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 SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets a dispatcher that processes events and forwards them to tools.
wxListBox * m_libList
#define ShowGridEntryKeyword
Nonzero to show grid (suffix)
Definition: draw_frame.h:66
void LoadSettings(wxConfigBase *aCfg) override
Load 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
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
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:542
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
void InitTools()
Function InitTools() Initializes all registered tools.
Definition for part library class.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
void DClickOnCmpList(wxCommandEvent &event)
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Set the screen cross hair position to aPosition in logical (drawing) units.
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.
ACTIONS * m_actions
Definition: draw_frame.h:132
#define GridColorEntryKeyword
Grid color ID (suffix)
Definition: draw_frame.h:68
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.
bool m_movingCursorWithKeyboard
One-shot to avoid a recursive mouse event during hotkey movement.
Definition: draw_frame.h:179
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...
#define CMPLIST_WIDTH_KEY
bool ProcessEvent(wxEvent &aEvent) override
Override 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
void RegisterTool(TOOL_BASE *aTool)
Function RegisterTool() Adds a tool to the manager set and sets it up.
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
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_ADD_FOOTPRINT_TO_BOARD
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.