KiCad PCB EDA Suite
lib_edit_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) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 2004-2020 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 <base_screen.h>
27 #include <class_library.h>
28 #include <confirm.h>
29 #include <eeschema_id.h>
30 #include <eeschema_settings.h>
31 #include <fctsys.h>
32 #include <general.h>
33 #include <kiface_i.h>
34 #include <kiway_express.h>
35 #include <lib_edit_frame.h>
36 #include <lib_manager.h>
37 #include <lib_text.h>
38 #include <libedit_settings.h>
39 #include <pgm_base.h>
40 #include <sch_draw_panel.h>
41 #include <sch_painter.h>
42 #include <sch_view.h>
44 #include <symbol_lib_table.h>
45 #include <tool/action_toolbar.h>
46 #include <tool/common_control.h>
47 #include <tool/common_tools.h>
48 #include <tool/picker_tool.h>
49 #include <tool/tool_dispatcher.h>
50 #include <tool/tool_manager.h>
51 #include <tool/zoom_tool.h>
52 #include <tools/ee_actions.h>
54 #include <tools/ee_point_editor.h>
56 #include <tools/lib_control.h>
58 #include <tools/lib_edit_tool.h>
59 #include <tools/lib_move_tool.h>
60 #include <tools/lib_pin_tool.h>
61 #include <widgets/infobar.h>
62 #include <widgets/lib_tree.h>
65 #include <wx/progdlg.h>
66 
67 
68 bool LIB_EDIT_FRAME:: m_showDeMorgan = false;
69 
70 BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
72  EVT_SIZE( LIB_EDIT_FRAME::OnSize )
73 
75 
76  // Right vertical toolbar.
79 
80  // menubar commands
81  EVT_MENU( wxID_EXIT, LIB_EDIT_FRAME::OnExitKiCad )
82  EVT_MENU( wxID_CLOSE, LIB_EDIT_FRAME::CloseWindow )
84 
85  // Update user interface elements.
87 
88 END_EVENT_TABLE()
89 
90 LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
91  SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_LIB_EDITOR, _( "Library Editor" ),
92  wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE,
94  m_unitSelectBox( nullptr )
95 {
96  SetShowDeMorgan( false );
97  m_SyncPinEdit = false;
98 
99  m_my_part = nullptr;
100  m_treePane = nullptr;
101  m_libMgr = nullptr;
102  m_unit = 1;
103  m_convert = 1;
104  m_AboutTitle = "LibEdit";
105 
106  wxIcon icon;
107  icon.CopyFromBitmap( KiBitmap( icon_libedit_xpm ) );
108  SetIcon( icon );
109 
110  m_settings = Pgm().GetSettingsManager().GetAppSettings<LIBEDIT_SETTINGS>();
111  LoadSettings( m_settings );
112 
113  // Ensure axis are always drawn
114  KIGFX::GAL_DISPLAY_OPTIONS& gal_opts = GetGalDisplayOptions();
115  gal_opts.m_axesEnabled = true;
116 
117  m_dummyScreen = new SCH_SCREEN();
118  SetScreen( m_dummyScreen );
119  GetScreen()->m_Center = true;
120  GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
121 
122  GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
123 
124  GetRenderSettings()->LoadColors( GetColorSettings() );
125 
126  setupTools();
127 
128  m_libMgr = new LIB_MANAGER( *this );
129  SyncLibraries( true );
130  m_treePane = new SYMBOL_TREE_PANE( this, m_libMgr );
131 
132  ReCreateMenuBar();
133  ReCreateHToolbar();
134  ReCreateVToolbar();
135  ReCreateOptToolbar();
136  InitExitKey();
137 
138  updateTitle();
139  DisplayCmpDoc();
140  RebuildSymbolUnitsList();
141 
142  // Create the infobar
143  m_infoBar = new WX_INFOBAR( this, &m_auimgr );
144 
145  m_auimgr.SetManagedWindow( this );
146 
147  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
148  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
149 
150  m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) );
151  m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "ComponentTree" ).Left().Layer(2)
152  .Caption( _( "Libraries" ) ).MinSize( 250, -1 )
153  .BestSize( m_settings->m_LibWidth, -1 ).Resizable() );
154  m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ).Right().Layer(2) );
155  m_auimgr.AddPane( m_infoBar,
156  EDA_PANE().InfoBar().Name( "InfoBar" ).Top().Layer(1) );
157 
158  m_auimgr.AddPane( GetCanvas(), wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
159 
160  // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
161  // hidding it.
162  m_auimgr.Update();
163 
164  // We don't want the infobar displayed right away
165  m_auimgr.GetPane( "InfoBar" ).Hide();
166  m_auimgr.Update();
167 
168  Raise();
169  Show( true );
170 
171  SyncView();
172  GetCanvas()->GetViewControls()->SetSnapping( true );
173  GetCanvas()->GetView()->UseDrawPriority( true );
174  GetCanvas()->GetGAL()->SetAxesEnabled( true );
175 
176  // Set the working/draw area size to display a symbol to a reasonable value:
177  // A 600mm x 600mm with a origin at the area center looks like a large working area
178  double max_size_x = Millimeter2iu( 600 );
179  double max_size_y = Millimeter2iu( 600 );
180  BOX2D bbox;
181  bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
182  bbox.SetSize( max_size_x, max_size_y );
183  GetCanvas()->GetView()->SetBoundary( bbox );
184 
185  m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
186 
187  SetShutdownBlockReason( _( "Library changes are unsaved" ) );
188 
189  // Ensure the window is on top
190  Raise();
191 }
192 
193 
195 {
196  // Shutdown all running tools
197  if( m_toolManager )
199 
200  // current screen is destroyed in EDA_DRAW_FRAME
202 
203  auto libedit = Pgm().GetSettingsManager().GetAppSettings<LIBEDIT_SETTINGS>();
204  Pgm().GetSettingsManager().Save( libedit );
205 
206  delete m_libMgr;
207 }
208 
209 
211 {
212  wxCHECK_RET( m_settings, "Call to LIB_EDIT_FRAME::LoadSettings with null m_settings" );
213 
215 
217 
218  // Hidden elements must be editable
222 }
223 
224 
226 {
227  wxCHECK_RET( m_settings, "Call to LIB_EDIT_FRAME::LoadSettings with null m_settings" );
228 
230 
232  m_settings->m_LibWidth = m_treePane->GetSize().x;
233 }
234 
235 
237 {
238  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
239 
240  if( GetSettings()->m_UseEeschemaColorSettings )
242  else
243  return mgr.GetColorSettings( GetSettings()->m_ColorTheme );
244 }
245 
246 
248 {
249  // Create the manager and dispatcher & route draw panel events to the dispatcher
252  GetCanvas()->GetViewControls(), config(), this );
253  m_actions = new EE_ACTIONS();
255 
256  // Register tools
270 
271  // Run the selection tool, it is supposed to be always active
272  m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
273 
275 }
276 
277 
278 void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
279 {
280  // Shutdown blocks must be determined and vetoed as early as possible
281  if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
282  && IsContentModified() )
283  {
284  aEvent.Veto();
285  return;
286  }
287 
288  if( saveAllLibraries( true ) )
289  Destroy();
290  else
291  aEvent.Veto();
292 }
293 
294 
296 {
297  if( !m_unitSelectBox )
298  return;
299 
300  if( m_unitSelectBox->GetCount() != 0 )
301  m_unitSelectBox->Clear();
302 
303  if( !m_my_part || m_my_part->GetUnitCount() <= 1 )
304  {
305  m_unit = 1;
306  m_unitSelectBox->Append( wxEmptyString );
307  }
308  else
309  {
310  for( int i = 0; i < m_my_part->GetUnitCount(); i++ )
311  {
312  wxString sub = LIB_PART::SubReference( i+1, false );
313  wxString unit = wxString::Format( _( "Unit %s" ), GetChars( sub ) );
314  m_unitSelectBox->Append( unit );
315  }
316  }
317 
318  // Ensure the selected unit is compatible with the number of units of the current part:
319  if( m_my_part && m_my_part->GetUnitCount() < m_unit )
320  m_unit = 1;
321 
322  m_unitSelectBox->SetSelection(( m_unit > 0 ) ? m_unit - 1 : 0 );
323 }
324 
325 
326 void LIB_EDIT_FRAME::OnToggleSearchTree( wxCommandEvent& event )
327 {
328  auto& treePane = m_auimgr.GetPane( m_treePane );
329  treePane.Show( !IsSearchTreeShown() );
330  m_auimgr.Update();
331 }
332 
333 
335 {
336  return m_auimgr.GetPane( m_treePane ).IsShown();
337 }
338 
339 
341 {
342  m_libMgr->GetAdapter()->Freeze();
343 }
344 
345 
347 {
348  m_libMgr->GetAdapter()->Thaw();
349 }
350 
351 
352 void LIB_EDIT_FRAME::OnExitKiCad( wxCommandEvent& event )
353 {
354  Kiway().OnKiCadExit();
355 }
356 
357 
358 void LIB_EDIT_FRAME::OnUpdatePartNumber( wxUpdateUIEvent& event )
359 {
360  if( !m_unitSelectBox )
361  return;
362 
363  // Using the typical event.Enable() call doesn't seem to work with wxGTK
364  // so use the pointer to alias combobox to directly enable or disable.
365  m_unitSelectBox->Enable( m_my_part && m_my_part->GetUnitCount() > 1 );
366 }
367 
368 
369 void LIB_EDIT_FRAME::OnSelectUnit( wxCommandEvent& event )
370 {
371  int i = event.GetSelection();
372 
373  if( ( i == wxNOT_FOUND ) || ( ( i + 1 ) == m_unit ) )
374  return;
375 
378 
379  m_unit = i + 1;
380 
382  RebuildView();
383 }
384 
385 
387 {
388  wxString libNickname = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_LIB );
389 
390  if( !libNickname.empty() )
391  {
392  if( !Prj().SchSymbolLibTable()->HasLibrary( libNickname ) )
393  {
394  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
395  libNickname = wxEmptyString;
396  }
397  }
398 
399  return libNickname;
400 }
401 
402 
403 wxString LIB_EDIT_FRAME::SetCurLib( const wxString& aLibNickname )
404 {
405  wxString old = GetCurLib();
406 
407  if( aLibNickname.empty() || !Prj().SchSymbolLibTable()->HasLibrary( aLibNickname ) )
408  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
409  else
410  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, aLibNickname );
411 
412  m_libMgr->SetCurrentLib( aLibNickname );
413 
414  ReCreateMenuBar();
415 
416  return old;
417 }
418 
419 
421 {
423 
424  delete m_my_part;
425  m_my_part = aPart;
426 
427  // select the current component in the tree widget
428  if( m_my_part )
430 
431  wxString partName = m_my_part ? m_my_part->GetName() : wxString();
432  m_libMgr->SetCurrentPart( partName );
433 
434  // retain in case this wxFrame is re-opened later on the same PROJECT
436 
437  // Ensure synchronized pin edit can be enabled only symbols with interchangeable units
438  m_SyncPinEdit = aPart && aPart->IsRoot() && aPart->IsMulti() && !aPart->UnitsLocked();
439 
441  RebuildView();
442 }
443 
444 
446 {
447  wxASSERT( m_libMgr );
448  return *m_libMgr;
449 }
450 
451 
452 void LIB_EDIT_FRAME::OnImportBody( wxCommandEvent& aEvent )
453 {
455  LoadOneSymbol();
456  m_drawToolBar->ToggleTool( ID_LIBEDIT_IMPORT_BODY_BUTT, false );
457 }
458 
459 
460 void LIB_EDIT_FRAME::OnExportBody( wxCommandEvent& aEvent )
461 {
463  SaveOneSymbol();
464  m_drawToolBar->ToggleTool( ID_LIBEDIT_EXPORT_BODY_BUTT, false );
465 }
466 
467 
469 {
470  GetScreen()->SetModify();
472 
474 }
475 
476 
478 {
480 }
481 
482 
484 {
485  // There may be no parent window so use KIWAY message to refresh the schematic editor
486  // in case any symbols have changed.
487  std::string dummyPayload;
488  Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_REFRESH, dummyPayload, this );
489 }
490 
491 
492 bool LIB_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
493 {
494  wxFileName fn = m_libMgr->GetUniqueLibraryName();
495 
496  if( !LibraryFileBrowser( !aCreateNew, fn, KiCadSymbolLibFileWildcard(),
497  KiCadSymbolLibFileExtension, false ) )
498  {
499  return false;
500  }
501 
502  wxString libName = fn.GetName();
503 
504  if( libName.IsEmpty() )
505  return false;
506 
507  if( m_libMgr->LibraryExists( libName ) )
508  {
509  DisplayError( this, wxString::Format( _( "Library \"%s\" already exists" ), libName ) );
510  return false;
511  }
512 
513  // Select the target library table (global/project)
514  SYMBOL_LIB_TABLE* libTable = selectSymLibTable();
515 
516  if( !libTable )
517  return false;
518 
519  if( aCreateNew )
520  {
521  if( !m_libMgr->CreateLibrary( fn.GetFullPath(), libTable ) )
522  {
523  DisplayError( this, wxString::Format( _( "Could not create the library file '%s'.\n"
524  "Check write permission." ),
525  fn.GetFullPath() ) );
526  return false;
527  }
528  }
529  else
530  {
531  if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
532  {
533  DisplayError( this, _( "Could not open the library file." ) );
534  return false;
535  }
536  }
537 
538  bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
539  saveSymbolLibTables( globalTable, !globalTable );
540 
541  return true;
542 }
543 
544 
546 {
547  return m_treePane->GetLibTree()->GetSelectedLibId( aUnit );
548 }
549 
550 
552 {
553  LIB_ID libId = GetTreeLIBID();
554 
555  if( libId.IsValid() )
556  {
557  LIB_PART* alias = m_libMgr->GetAlias( libId.GetLibItemName(), libId.GetLibNickname() );
558  return alias;
559  }
560 
561  return m_my_part;
562 }
563 
564 
566 {
567  LIB_ID id = GetTreeLIBID();
568 
569  if( id.GetLibNickname().empty() && m_my_part )
570  id = m_my_part->GetLibId();
571 
572  return id;
573 }
574 
575 
577 {
579 }
580 
581 
583 {
584  return getTargetLibId().GetLibNickname();
585 }
586 
587 
588 void LIB_EDIT_FRAME::SyncLibraries( bool aShowProgress )
589 {
590  LIB_ID selected;
591 
592  if( m_treePane )
593  selected = m_treePane->GetLibTree()->GetSelectedLibId();
594 
595  if( aShowProgress )
596  {
597  wxProgressDialog progressDlg( _( "Loading Symbol Libraries" ), wxEmptyString,
598  m_libMgr->GetAdapter()->GetLibrariesCount(), this );
599 
600  m_libMgr->Sync( true, [&]( int progress, int max, const wxString& libName )
601  {
602  progressDlg.Update( progress, wxString::Format( _( "Loading library \"%s\"" ),
603  libName ) );
604  } );
605  }
606  else
607  {
608  m_libMgr->Sync( true );
609  }
610 
611  if( m_treePane )
612  {
613  wxDataViewItem found;
614 
615  if( selected.IsValid() )
616  {
617  // Check if the previously selected item is still valid,
618  // if not - it has to be unselected to prevent crash
619  found = m_libMgr->GetAdapter()->FindItem( selected );
620 
621  if( !found )
623  }
624 
625  m_treePane->GetLibTree()->Regenerate( true );
626 
627  // Try to select the parent library, in case the part is not found
628  if( !found && selected.IsValid() )
629  {
630  selected.SetLibItemName( "" );
631  found = m_libMgr->GetAdapter()->FindItem( selected );
632 
633  if( found )
634  m_treePane->GetLibTree()->SelectLibId( selected );
635  }
636 
637  // If no selection, see if there's a current part to centre
638  if( !selected.IsValid() && m_my_part )
639  {
640  LIB_ID current( GetCurLib(), m_my_part->GetName() );
641  m_treePane->GetLibTree()->CenterLibId( current );
642  }
643  }
644 }
645 
646 
648 {
649  LIB_ID target = getTargetLibId();
650 
651  m_treePane->GetLibTree()->Regenerate( true );
652 
653  if( target.IsValid() )
654  m_treePane->GetLibTree()->CenterLibId( target );
655 }
656 
657 
659 {
660  wxArrayString libTableNames;
661  libTableNames.Add( _( "Global" ) );
662  libTableNames.Add( _( "Project" ) );
663 
664  wxSingleChoiceDialog dlg( this, _( "Choose the Library Table to add the library to:" ),
665  _( "Add To Library Table" ), libTableNames );
666 
667  if( aOptional )
668  {
669  dlg.FindWindow( wxID_CANCEL )->SetLabel( _( "Skip" ) );
670  dlg.FindWindow( wxID_OK )->SetLabel( _( "Add" ) );
671  }
672 
673  if( dlg.ShowModal() != wxID_OK )
674  return nullptr;
675 
676  switch( dlg.GetSelection() )
677  {
678  case 0: return &SYMBOL_LIB_TABLE::GetGlobalLibTable();
679  case 1: return Prj().SchSymbolLibTable();
680  default: return nullptr;
681  }
682 }
683 
684 
685 bool LIB_EDIT_FRAME::backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt )
686 {
687  if( aOriginalFile.FileExists() )
688  {
689  wxFileName backupFileName( aOriginalFile );
690  backupFileName.SetExt( aBackupExt );
691 
692  if( backupFileName.FileExists() )
693  wxRemoveFile( backupFileName.GetFullPath() );
694 
695  if( !wxCopyFile( aOriginalFile.GetFullPath(), backupFileName.GetFullPath() ) )
696  {
697  DisplayError( this, wxString::Format( _( "Failed to save backup to \"%s\"" ),
698  backupFileName.GetFullPath() ) );
699  return false;
700  }
701  }
702 
703  return true;
704 }
705 
706 
708 {
709  if( m_my_part && !GetCurLib().IsEmpty() && GetScreen()->IsModify() )
710  m_libMgr->UpdatePart( m_my_part, GetCurLib() ); // UpdatePart() makes a copy
711 }
712 
713 
714 bool LIB_EDIT_FRAME::isCurrentPart( const LIB_ID& aLibId ) const
715 {
716  // This will return the root part of any alias
717  LIB_PART* part = m_libMgr->GetBufferedPart( aLibId.GetLibItemName(), aLibId.GetLibNickname() );
718  // Now we can compare the libId of the current part and the root part
719  return ( part && m_my_part && part->GetLibId() == m_my_part->GetLibId() );
720 }
721 
722 
724 {
726  SetCurLib( wxEmptyString );
727  SetCurPart( nullptr );
731  Refresh();
732 }
733 
734 
735 void LIB_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
736 {
737  SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
738 
740 
742 
743  if( aEnvVarsChanged )
744  SyncLibraries( true );
745 
746  Layout();
747  SendSizeEvent();
748 }
749 
750 
752 {
753  // call my base class
755 
756  // tooltips in toolbars
758 
759  // status bar
760  UpdateMsgPanel();
761 }
762 
763 
765 {
766  SCH_BASE_FRAME::SetScreen( aScreen );
767 }
768 
769 
771 {
778 
779  GetCanvas()->Refresh();
780 }
781 
782 
784 {
785  SyncLibraries( true );
786 
787  if( m_my_part )
788  {
790  EE_SELECTION& selection = selectionTool->GetSelection();
791 
792  for( LIB_ITEM& item : m_my_part->GetDrawItems() )
793  {
794  if( std::find( selection.begin(), selection.end(), &item ) == selection.end() )
795  item.ClearSelected();
796  else
797  item.SetSelected();
798  }
799  }
800 
801  RebuildView();
802 }
803 
804 
806 {
807  if( !m_my_part )
808  {
809  return BOX2I( VECTOR2I( Mils2iu( -100 ), Mils2iu( -100 ) ),
810  VECTOR2I( Mils2iu( 200 ), Mils2iu( 200 ) ) );
811  }
812  else
813  {
814  EDA_RECT boundingBox = m_my_part->Flatten()->GetUnitBoundingBox( m_unit, m_convert );
816  boundingBox.GetHeight() ) );
817  }
818 }
819 
820 
822 {
823  const std::string& payload = mail.GetPayload();
824 
825  switch( mail.Command() )
826  {
827  case MAIL_LIB_EDIT:
828  if( !payload.empty() )
829  {
830  wxString libFileName( payload );
831  wxString libNickname;
832  wxString msg;
833 
834  SYMBOL_LIB_TABLE* libTable = Prj().SchSymbolLibTable();
835  const LIB_TABLE_ROW* libTableRow = libTable->FindRowByURI( libFileName );
836 
837  if( !libTableRow )
838  {
839  msg.Printf( _( "The current configuration does not include the symbol library\n"
840  "\"%s\".\nUse Manage Symbol Libraries to edit the configuration." ),
841  libFileName );
842  DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
843  break;
844  }
845 
846  libNickname = libTableRow->GetNickName();
847 
848  if( !libTable->HasLibrary( libNickname, true ) )
849  {
850  msg.Printf( _( "The library with the nickname \"%s\" is not enabled\n"
851  "in the current configuration. Use Manage Symbol Libraries to\n"
852  "edit the configuration." ), libNickname );
853  DisplayErrorMessage( this, _( "Symbol library not enabled." ), msg );
854  break;
855  }
856 
857  SetCurLib( libNickname );
858 
859  if( m_treePane )
860  {
861  LIB_ID id( libNickname, wxEmptyString );
864  }
865  }
866 
867  break;
868 
869  default:
870  ;
871  }
872 }
873 
874 
876 {
877  // switches currently used canvas ( Cairo / OpenGL):
878  SCH_BASE_FRAME::SwitchCanvas( aCanvasType );
879 
880  // Set options specific to symbol editor (axies are always enabled):
881  GetCanvas()->GetGAL()->SetAxesEnabled( true );
883 }
884 
885 
887 {
888  wxCHECK( m_libMgr, false );
889 
890  return m_libMgr->HasModifications();
891 }
892 
893 
895 {
896  wxCHECK( m_libMgr, false );
897 
898  // Test if the currently edited part is modified
899  if( GetScreen() && GetScreen()->IsModify() && GetCurPart() )
900  return true;
901 
902  // Test if any library has been modified
903  for( const auto& libNickname : m_libMgr->GetLibraryNames() )
904  {
905  if( m_libMgr->IsLibraryModified( libNickname )
906  && !m_libMgr->IsLibraryReadOnly( libNickname ) )
907  return true;
908  }
909 
910  return false;
911 }
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
void Sync(bool aForce=false, std::function< void(int, int, const wxString &)> aProgressCallback=[](int, int, const wxString &){})
Updates the LIB_MANAGER data to synchronize with Symbol Library Table.
Definition: lib_manager.cpp:49
KIGFX::SCH_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
void OnToggleSearchTree(wxCommandEvent &event)
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
void OnUpdatePartNumber(wxUpdateUIEvent &event)
BOX2< VECTOR2I > BOX2I
Definition: box2.h:521
void SaveOneSymbol()
Saves the current symbol to a symbol file.
Definition: symbedit.cpp:143
KIWAY_EXPRESS carries a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:39
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
void OnKiCadExit()
Definition: kiway.cpp:523
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition: sch_view.cpp:215
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
LIB_ID GetLibId() const override
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
void HardRedraw() override
Rebuild the GAL and redraw the screen.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
wxString GetName() const override
Model changes (required full reload)
Definition: tool_base.h:82
This file is part of the common library.
virtual void SetScreen(BASE_SCREEN *aScreen)
LIB_DRAWING_TOOLS.
LIBEDIT_SETTINGS * m_settings
void KiwayMailIn(KIWAY_EXPRESS &mail) override
Function KiwayMailIn receives KIWAY_EXPRESS messages from other players.
void OnImportBody(wxCommandEvent &aEvent)
void OnCloseWindow(wxCloseEvent &Event)
bool CreateLibrary(const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
Creates an empty library and adds it to the library table.
Definition: lib_manager.h:138
LIB_MANAGER * m_libMgr
static TOOL_ACTION cancelInteractive
Definition: actions.h:65
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
void RecreateToolbars()
Rebuild all toolbars, and update the checked state of ckeck tools.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
void SetSize(const Vec &size)
Definition: box2.h:211
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
void LoadOneSymbol()
Read a component symbol file (*.sym ) and add graphic items to the current component.
Definition: symbedit.cpp:43
void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType) override
switches currently used canvas ( Cairo / OpenGL).
LIB_PART * GetCurPart()
Return the current part being edited or NULL if none selected.
wxAuiManager m_auimgr
bool isCurrentPart(const LIB_ID &aLibId) const
Returns true if aLibId is an alias for the editor screen part.
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.
bool IsValid() const
Definition: lib_id.h:171
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
void CloseWindow(wxCommandEvent &event)
Trigger the wxCloseEvent, which is handled by the function given to EVT_CLOSE() macro:
void DeactivateTool()
Function DeactivateTool() Deactivates the currently active tool.
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID.
LIB_PART * m_my_part
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
The base class for drawable items used by schematic library components.
Definition: lib_item.h:61
void RegenerateLibraryTree()
Filter, sort, and redisplay the library tree.
bool m_axesEnabled
Whether or not to draw the coordinate system axes
Library Editor pane with component tree and symbol library table selector.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void OnExportBody(wxCommandEvent &aEvent)
LIB_CONTROL.
Definition: lib_control.h:39
LIB_PART * GetAlias(const wxString &aAlias, const wxString &aLibrary) const
Returns either an alias of a working LIB_PART copy, or alias of the original part if there is no work...
#define LIB_EDIT_FRAME_NAME
EE_SELECTION & GetSelection()
Function GetSelection()
bool AddLibraryFile(bool aCreateNew)
Creates or adds an existing library to the symbol library table.
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:60
TOOL_MANAGER.
Definition: tool_manager.h:51
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
LIB_ID GetTreeLIBID(int *aUnit=nullptr) const
Return the LIB_ID of the library or symbol selected in the symbol tree.
const wxString & GetNickName() const
void HideWorksheet()
Definition: sch_view.cpp:222
bool AddLibrary(const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
Adds an existing library.
Definition: lib_manager.h:146
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:91
const BOX2I GetDocumentExtents() const override
int GetUnitCount() const override
For items with units, return the number of units.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:166
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void ReCreateMenuBar() override
Recreates the menu bar.
wxString GetUniqueLibraryName() const
Returns a library name that is not currently in use.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
const LIB_TABLE_ROW * FindRowByURI(const wxString &aURI)
BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:44
coord_type GetWidth() const
Definition: box2.h:196
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit components, if the user selects the component itself rather than picking an individual...
Definition: lib_tree.cpp:148
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
Definition: base_screen.cpp:73
ACTIONS * m_actions
Definition: tools_holder.h:49
Define a library symbol object.
void Regenerate(bool aKeepState)
Regenerates the tree.
Definition: lib_tree.cpp:200
Definition of file extensions used in Kicad.
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:189
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Function ResetTools() Resets all tools (i.e.
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false)
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
bool saveSymbolLibTables(bool aGlobal, bool aProject)
Saves Symbol Library Tables to disk.
wxArrayString GetLibraryNames() const
Returns the array of library names.
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
AppSettings * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
wxString KiCadSymbolLibFileWildcard()
virtual void OnSize(wxSizeEvent &event)
Recalculate the size of toolbars and display panel when the frame size changes.
#define KICAD_DEFAULT_DRAWFRAME_STYLE
void SetCurrentLib(const wxString &aLibrary)
Definition: lib_manager.h:277
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
void SetCurrentPart(const wxString &aPart)
Definition: lib_manager.h:283
void CommonSettingsChanged(bool aEnvVarsChanged) override
Called after the preferences dialog is run.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
std::unique_ptr< LIB_PART > Flatten() const
Return a flattened symbol inheritance to the caller.
COMMON_CONTROL.
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:218
void SetAxesEnabled(bool aAxesEnabled)
Enables drawing the axes.
The the schematic editor to refresh the display.
Definition: mail_type.h:48
Specialization of the wxAuiPaneInfo class for KiCad panels.
void RebuildSymbolUnitsList()
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:206
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:50
EESCHEMA_ACTIONS.
Definition: ee_actions.h:41
COMMON_TOOLS.
Definition: common_tools.h:38
void emptyScreen()
Restores the empty editor screen, without any part or library selected.
TOOL_DISPATCHER.
COLOR_SETTINGS * m_colorSettings
bool UpdatePart(LIB_PART *aPart, const wxString &aLibrary)
Updates the part buffer with a new version of the part.
VTBL_ENTRY void SetRString(RSTRING_T aStringId, const wxString &aString)
Function SetRString stores a "retained string", which is any session and project specific string iden...
Definition: project.cpp:206
bool IsContentModified() override
Get if any parts or libraries have been modified but not saved.
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
Class to handle modifications to the symbol libraries.
Definition: lib_manager.h:99
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition: lib_tree.cpp:194
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void storeCurrentPart()
Stores the currently modified part in the library manager buffer.
VTBL_ENTRY void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=NULL)
Function ExpressMail send aPayload to aDestination from aSource.
Definition: kiway.cpp:428
bool backupFile(const wxFileName &aOriginalFile, const wxString &aBackupExt)
Creates a backup copy of a file with requested extension
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:68
void SyncLibraries(bool aShowProgress)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
const BITMAP_OPAQUE icon_libedit_xpm[1]
COLOR4D GetColor(int aLayer) const
VTBL_ENTRY const wxString & GetRString(RSTRING_T aStringId)
Function GetRString returns a "retained string", which is any session and project specific string ide...
Definition: project.cpp:221
LIB_PART * GetBufferedPart(const wxString &aAlias, const wxString &aLibrary)
Returns the part copy from the buffer.
The symbol library editor main window.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
see class PGM_BASE
bool m_SyncPinEdit
Set to true to synchronize pins at the same position when editing symbols with multiple units or mult...
bool HasLibModifications() const
Check if any pending libraries have been modified.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
bool saveAllLibraries(bool aRequireConfirmation)
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
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Changes the current rendering backend.
void SetCurPart(LIB_PART *aPart)
Take ownership of aPart and notes that it is the one currently being edited.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Sets the work environment (model, view, view controls and the parent window).
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets a dispatcher that processes events and forwards them to tools.
#define _(s)
Definition: 3d_actions.cpp:33
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
EE_POINT_EDITOR.
void SetScreen(BASE_SCREEN *aScreen) override
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnToggleShowLayerManager GERBVIEW_FRAME::OnSelectHighlightChoice EVT_UPDATE_UI(ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnUpdateLayerSelectBox) EVT_UPDATE_UI_RANGE(ID_TB_OPTIONS_SHOW_GBR_MODE_0
bool IsAlias() const
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
void SetOrigin(const Vec &pos)
Definition: box2.h:209
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
static wxString SubReference(int aUnit, bool aAddSeparator=true)
LIB_ID getTargetLibId() const
Returns either the part selected in the component tree, if context menu is active or the currently mo...
static bool empty(const wxTextEntryBase *aCtrl)
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
coord_type GetHeight() const
Definition: box2.h:197
LIBEDIT_SETTINGS * GetSettings()
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current symbol.
void OnSelectUnit(wxCommandEvent &event)
bool IsMulti() const
bool HasModifications() const
Definition: lib_manager.cpp:66
LIB_PART * getTargetPart() const
Returns currently edited part.
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
bool IsLibraryModified(const wxString &aLibrary) const
Returns true if library has unsaved modifications.
Color settings are a bit different than most of the settings objects in that there can be more than o...
SCH_SCREEN * m_dummyScreen
Helper screen used when no part is loaded
wxString SetCurLib(const wxString &aLibNickname)
Sets the current library nickname and returns the old library nickname.
void OnGridSettings(wxCommandEvent &event)
SYMBOL_LIB_TABLE * selectSymLibTable(bool aOptional=false)
Displays a dialog asking the user to select a symbol library table.
void InitTools()
Function InitTools() Initializes all registered tools.
COLOR_SETTINGS * GetColorSettings() override
Returns a pointer to the active color theme settings.
Definition for part library class.
const Vec & GetOrigin() const
Definition: box2.h:192
wxComboBox * m_unitSelectBox
void SetModify()
Definition: base_screen.h:183
MAIL_T Command()
Function Command returns the MAIL_T associated with this mail.
Definition: kiway_express.h:52
LIB_TREE * GetLibTree() const
SYMBOL_TREE_PANE * m_treePane
LIB_MANAGER & GetLibManager()
BASE_SCREEN class implementation.
LIB_TREE_NODE * GetCurrentTreeNode() const
LIB_TREE_MODEL_ADAPTER::PTR & GetAdapter()
Returns the adapter object that provides the stored data.
Definition: lib_manager.h:271
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
virtual void ShowChangedLanguage()
Redraw the menus and what not in current language.
void DisplayComponent(const LIB_PART *aComponent)
std::string & GetPayload()
Function Payload returns the payload, which can be any text but it typicall self identifying s-expres...
Definition: kiway_express.h:62
bool IsLibraryReadOnly(const wxString &aLibrary) const
Returns true if the library is stored in a read-only file.
bool UnitsLocked() const
Check whether part units are interchangeable.
~LIB_EDIT_FRAME() override
wxString getTargetLib() const
Returns either the library selected in the component tree, if context menu is active or the library t...
void RegisterTool(TOOL_BASE *aTool)
Function RegisterTool() Adds a tool to the manager set and sets it up.
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferrably centered).
Definition: lib_tree.cpp:183
void OnExitKiCad(wxCommandEvent &event)
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:177
virtual void UpdateMsgPanel()
Redraw the message panel.
const std::string KiCadSymbolLibFileExtension
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:156
ACTION_TOOLBAR * m_drawToolBar