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-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 <pgm_base.h>
28 #include <kiface_i.h>
29 #include <kiway_express.h>
30 #include <sch_draw_panel.h>
31 #include <base_screen.h>
32 #include <confirm.h>
33 #include <general.h>
34 #include <eeschema_id.h>
35 #include <lib_edit_frame.h>
36 #include <class_library.h>
37 #include <lib_manager.h>
39 #include <widgets/lib_tree.h>
40 #include <symbol_lib_table.h>
42 #include <wx/progdlg.h>
43 #include <tool/tool_manager.h>
44 #include <tool/tool_dispatcher.h>
45 #include <tool/action_toolbar.h>
46 #include <tool/common_control.h>
47 #include <tool/picker_tool.h>
48 #include <tool/common_tools.h>
49 #include <tool/zoom_tool.h>
50 #include <tools/ee_actions.h>
53 #include <tools/lib_pin_tool.h>
54 #include <tools/lib_edit_tool.h>
55 #include <tools/lib_move_tool.h>
57 #include <tools/lib_control.h>
58 #include <tools/ee_point_editor.h>
59 #include <sch_view.h>
60 #include <sch_painter.h>
61 
62 
63 bool LIB_EDIT_FRAME:: m_showDeMorgan = false;
64 int LIB_EDIT_FRAME:: g_LastTextSize = -1;
65 double LIB_EDIT_FRAME:: g_LastTextAngle = TEXT_ANGLE_HORIZ;
66 int LIB_EDIT_FRAME:: g_LastLineWidth = 0;
67 
68 // these values are overridden when reading the config
69 int LIB_EDIT_FRAME:: m_textPinNumDefaultSize = DEFAULTPINNUMSIZE;
70 int LIB_EDIT_FRAME:: m_textPinNameDefaultSize = DEFAULTPINNAMESIZE;
71 int LIB_EDIT_FRAME:: m_defaultPinLength = DEFAULTPINLENGTH;
72 
73 FILL_T LIB_EDIT_FRAME:: g_LastFillStyle = NO_FILL;
74 
75 
76 BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
78  EVT_SIZE( LIB_EDIT_FRAME::OnSize )
79 
81 
82  // Right vertical toolbar.
85 
86  // menubar commands
87  EVT_MENU( wxID_EXIT, LIB_EDIT_FRAME::OnExitKiCad )
88  EVT_MENU( wxID_CLOSE, LIB_EDIT_FRAME::CloseWindow )
90 
91  // Update user interface elements.
93 
94 END_EVENT_TABLE()
95 
96 LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
97  SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_LIB_EDITOR, _( "Library Editor" ),
98  wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, LIB_EDIT_FRAME_NAME )
99 {
100  SetShowDeMorgan( false );
101  m_DrawSpecificConvert = true;
102  m_DrawSpecificUnit = false;
103  m_SyncPinEdit = false;
104  m_repeatPinStep = DEFAULT_REPEAT_OFFSET_PIN;
105  SetShowElectricalType( true );
106  m_FrameSize = ConvertDialogToPixels( wxSize( 500, 350 ) ); // default in case of no prefs
107 
108  m_my_part = nullptr;
109  m_treePane = nullptr;
110  m_libMgr = nullptr;
111  m_unit = 1;
112  m_convert = 1;
113  m_AboutTitle = "LibEdit";
114 
115  // Delayed initialization
116  if( g_LastTextSize == -1 )
117  g_LastTextSize = GetDefaultTextSize();
118 
119  // Initialize grid id to the default value 50 mils:
121 
122  wxIcon icon;
123  icon.CopyFromBitmap( KiBitmap( icon_libedit_xpm ) );
124  SetIcon( icon );
125 
126  LoadSettings( config() );
127 
128  // Ensure axis are always drawn
129  KIGFX::GAL_DISPLAY_OPTIONS& gal_opts = GetGalDisplayOptions();
130  gal_opts.m_axesEnabled = true;
131 
132  m_dummyScreen = new SCH_SCREEN( aKiway );
133  SetScreen( m_dummyScreen );
134  GetScreen()->m_Center = true;
135  GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
136 
137  GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
138  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
139 
140  setupTools();
141 
142  m_libMgr = new LIB_MANAGER( *this );
143  SyncLibraries( true );
144  m_treePane = new SYMBOL_TREE_PANE( this, m_libMgr );
145 
146  ReCreateMenuBar();
147  ReCreateHToolbar();
148  ReCreateVToolbar();
149  ReCreateOptToolbar();
150  InitExitKey();
151 
152  updateTitle();
153  DisplayCmpDoc();
154  RebuildSymbolUnitsList();
155 
156  m_auimgr.SetManagedWindow( this );
157 
158  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
159  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
160 
161  m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) );
162  m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "ComponentTree" ).Left().Layer(1)
163  .Caption( _( "Libraries" ) ).MinSize( 250, -1 )
164  .BestSize( m_defaultLibWidth, -1 ).Resizable() );
165  m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ).Right().Layer(1) );
166 
167  m_auimgr.AddPane( GetCanvas(), wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
168 
169  m_auimgr.Update();
170 
171  GetToolManager()->RunAction( "common.Control.gridPreset", true, m_LastGridSizeId );
172 
173  Raise();
174  Show( true );
175 
176  SyncView();
177  GetCanvas()->GetViewControls()->SetSnapping( true );
178  GetCanvas()->GetView()->UseDrawPriority( true );
179  GetCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
180  GetCanvas()->GetGAL()->SetAxesEnabled( true );
181 
182  // Set the working/draw area size to display a symbol to a reasonable value:
183  // A 600mm x 600mm with a origin at the area center looks like a large working area
184  double max_size_x = Millimeter2iu( 600 );
185  double max_size_y = Millimeter2iu( 600 );
186  BOX2D bbox;
187  bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
188  bbox.SetSize( max_size_x, max_size_y );
189  GetCanvas()->GetView()->SetBoundary( bbox );
190 
191  m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
192 }
193 
194 
196 {
197  // current screen is destroyed in EDA_DRAW_FRAME
199 
200  delete m_libMgr;
201 }
202 
203 
205 {
206  // Create the manager and dispatcher & route draw panel events to the dispatcher
209  GetCanvas()->GetViewControls(), this );
210  m_actions = new EE_ACTIONS();
212 
213  // Register tools
227 
228  // Run the selection tool, it is supposed to be always active
229  m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
230 
232 }
233 
234 
235 void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
236 {
237  if( saveAllLibraries( true ) )
238  Destroy();
239  else
240  Event.Veto();
241 }
242 
243 
245 {
246  if( !m_unitSelectBox )
247  return;
248 
249  if( m_unitSelectBox->GetCount() != 0 )
250  m_unitSelectBox->Clear();
251 
252  if( !m_my_part || m_my_part->GetUnitCount() <= 1 )
253  {
254  m_unit = 1;
255  m_unitSelectBox->Append( wxEmptyString );
256  }
257  else
258  {
259  for( int i = 0; i < m_my_part->GetUnitCount(); i++ )
260  {
261  wxString sub = LIB_PART::SubReference( i+1, false );
262  wxString unit = wxString::Format( _( "Unit %s" ), GetChars( sub ) );
263  m_unitSelectBox->Append( unit );
264  }
265  }
266 
267  // Ensure the selected unit is compatible with the number of units of the current part:
268  if( m_my_part && m_my_part->GetUnitCount() < m_unit )
269  m_unit = 1;
270 
271  m_unitSelectBox->SetSelection(( m_unit > 0 ) ? m_unit - 1 : 0 );
272 }
273 
274 
275 void LIB_EDIT_FRAME::OnToggleSearchTree( wxCommandEvent& event )
276 {
277  auto& treePane = m_auimgr.GetPane( m_treePane );
278  treePane.Show( !IsSearchTreeShown() );
279  m_auimgr.Update();
280 }
281 
282 
284 {
285  return m_auimgr.GetPane( m_treePane ).IsShown();
286 }
287 
288 
290 {
291  m_libMgr->GetAdapter()->Freeze();
292 }
293 
294 
296 {
297  m_libMgr->GetAdapter()->Thaw();
298 }
299 
300 
301 void LIB_EDIT_FRAME::OnExitKiCad( wxCommandEvent& event )
302 {
303  Kiway().OnKiCadExit();
304 }
305 
306 
307 void LIB_EDIT_FRAME::OnUpdatePartNumber( wxUpdateUIEvent& event )
308 {
309  if( !m_unitSelectBox )
310  return;
311 
312  // Using the typical event.Enable() call doesn't seem to work with wxGTK
313  // so use the pointer to alias combobox to directly enable or disable.
314  m_unitSelectBox->Enable( m_my_part && m_my_part->GetUnitCount() > 1 );
315 }
316 
317 
318 void LIB_EDIT_FRAME::OnSelectUnit( wxCommandEvent& event )
319 {
320  int i = event.GetSelection();
321 
322  if( ( i == wxNOT_FOUND ) || ( ( i + 1 ) == m_unit ) )
323  return;
324 
327 
328  m_unit = i + 1;
329 
331  RebuildView();
332 }
333 
334 
336 {
337  wxString libNickname = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_LIB );
338 
339  if( !libNickname.empty() )
340  {
341  if( !Prj().SchSymbolLibTable()->HasLibrary( libNickname ) )
342  {
343  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
344  libNickname = wxEmptyString;
345  }
346  }
347 
348  return libNickname;
349 }
350 
351 
352 wxString LIB_EDIT_FRAME::SetCurLib( const wxString& aLibNickname )
353 {
354  wxString old = GetCurLib();
355 
356  if( aLibNickname.empty() || !Prj().SchSymbolLibTable()->HasLibrary( aLibNickname ) )
357  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
358  else
359  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, aLibNickname );
360 
361  m_libMgr->SetCurrentLib( aLibNickname );
362 
363  return old;
364 }
365 
366 
368 {
370 
371  if( m_my_part )
372  delete m_my_part;
373 
374  m_my_part = aPart;
375 
376  // select the current component in the tree widget
377  if( m_my_part )
378  {
381  }
382 
383  wxString partName = m_my_part ? m_my_part->GetName() : wxString();
384  m_libMgr->SetCurrentPart( partName );
385 
386  // retain in case this wxFrame is re-opened later on the same PROJECT
388 
389  // Ensure synchronized pin edit can be enabled only symbols with interchangeable units
390  m_SyncPinEdit = aPart && aPart->IsRoot() && aPart->IsMulti() && !aPart->UnitsLocked();
391 
393  RebuildView();
394  SyncLibraries( false );
395 }
396 
397 
399 {
400  wxASSERT( m_libMgr );
401  return *m_libMgr;
402 }
403 
404 
405 void LIB_EDIT_FRAME::OnImportBody( wxCommandEvent& aEvent )
406 {
408  LoadOneSymbol();
409  m_drawToolBar->ToggleTool( ID_LIBEDIT_IMPORT_BODY_BUTT, false );
410 }
411 
412 
413 void LIB_EDIT_FRAME::OnExportBody( wxCommandEvent& aEvent )
414 {
416  SaveOneSymbol();
417  m_drawToolBar->ToggleTool( ID_LIBEDIT_EXPORT_BODY_BUTT, false );
418 }
419 
420 
422 {
423  GetScreen()->SetModify();
425 
427 }
428 
429 
431 {
433 }
434 
435 
437 {
438  // There may be no parent window so use KIWAY message to refresh the schematic editor
439  // in case any symbols have changed.
440  std::string dummyPayload;
441  Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_REFRESH, dummyPayload, this );
442 }
443 
444 
445 bool LIB_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
446 {
447  wxFileName fn = m_libMgr->GetUniqueLibraryName();
448 
449  if( !LibraryFileBrowser( !aCreateNew, fn, SchematicLibraryFileWildcard(),
451  {
452  return false;
453  }
454 
455  wxString libName = fn.GetName();
456 
457  if( libName.IsEmpty() )
458  return false;
459 
460  if( m_libMgr->LibraryExists( libName ) )
461  {
462  DisplayError( this, wxString::Format( _( "Library \"%s\" already exists" ), libName ) );
463  return false;
464  }
465 
466  // Select the target library table (global/project)
467  SYMBOL_LIB_TABLE* libTable = selectSymLibTable();
468 
469  if( !libTable )
470  return false;
471 
472  if( aCreateNew )
473  {
474  if( !m_libMgr->CreateLibrary( fn.GetFullPath(), libTable ) )
475  {
476  DisplayError( this, wxString::Format( _( "Could not create the library file '%s'.\n"
477  "Check write permission." ),
478  fn.GetFullPath() ) );
479  return false;
480  }
481  }
482  else
483  {
484  if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
485  {
486  DisplayError( this, _( "Could not open the library file." ) );
487  return false;
488  }
489  }
490 
491  bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
492  saveSymbolLibTables( globalTable, !globalTable );
493 
494  return true;
495 }
496 
497 
499 {
500  return m_treePane->GetLibTree()->GetSelectedLibId( aUnit );
501 }
502 
503 
505 {
506  LIB_ID libId = GetTreeLIBID();
507 
508  if( libId.IsValid() )
509  {
510  LIB_PART* alias = m_libMgr->GetAlias( libId.GetLibItemName(), libId.GetLibNickname() );
511  return alias;
512  }
513 
514  return m_my_part;
515 }
516 
517 
519 {
520  LIB_ID id = GetTreeLIBID();
521 
522  if( id.GetLibNickname().empty() && m_my_part )
523  id = m_my_part->GetLibId();
524 
525  return id;
526 }
527 
528 
530 {
531  return getTargetLibId().GetLibNickname();
532 }
533 
534 
535 void LIB_EDIT_FRAME::SyncLibraries( bool aShowProgress )
536 {
537  LIB_ID selected;
538 
539  if( m_treePane )
540  selected = m_treePane->GetLibTree()->GetSelectedLibId();
541 
542  if( aShowProgress )
543  {
544  wxProgressDialog progressDlg( _( "Loading Symbol Libraries" ), wxEmptyString,
545  m_libMgr->GetAdapter()->GetLibrariesCount(), this );
546 
547  m_libMgr->Sync( true, [&]( int progress, int max, const wxString& libName )
548  {
549  progressDlg.Update( progress, wxString::Format( _( "Loading library \"%s\"" ),
550  libName ) );
551  } );
552  }
553  else
554  {
555  m_libMgr->Sync( true );
556  }
557 
558  if( m_treePane )
559  {
560  wxDataViewItem found;
561 
562  if( selected.IsValid() )
563  {
564  // Check if the previously selected item is still valid,
565  // if not - it has to be unselected to prevent crash
566  found = m_libMgr->GetAdapter()->FindItem( selected );
567 
568  if( !found )
570  }
571 
573 
574  // Try to select the parent library, in case the part is not found
575  if( !found && selected.IsValid() )
576  {
577  selected.SetLibItemName( "" );
578  found = m_libMgr->GetAdapter()->FindItem( selected );
579 
580  if( found )
581  m_treePane->GetLibTree()->SelectLibId( selected );
582  }
583 
584  // If no selection, see if there's a current part to centre
585  if( !selected.IsValid() && m_my_part )
586  {
587  LIB_ID current( GetCurLib(), m_my_part->GetName() );
588  m_treePane->GetLibTree()->CenterLibId( current );
589  }
590  }
591 }
592 
593 
595 {
596  wxArrayString libTableNames;
597  libTableNames.Add( _( "Global" ) );
598  libTableNames.Add( _( "Project" ) );
599 
600  wxSingleChoiceDialog dlg( this, _( "Choose the Library Table to add the library to:" ),
601  _( "Add To Library Table" ), libTableNames );
602 
603  if( aOptional )
604  {
605  dlg.FindWindow( wxID_CANCEL )->SetLabel( _( "Skip" ) );
606  dlg.FindWindow( wxID_OK )->SetLabel( _( "Add" ) );
607  }
608 
609  if( dlg.ShowModal() != wxID_OK )
610  return nullptr;
611 
612  switch( dlg.GetSelection() )
613  {
614  case 0: return &SYMBOL_LIB_TABLE::GetGlobalLibTable();
615  case 1: return Prj().SchSymbolLibTable();
616  default: return nullptr;
617  }
618 }
619 
620 
621 bool LIB_EDIT_FRAME::backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt )
622 {
623  if( aOriginalFile.FileExists() )
624  {
625  wxFileName backupFileName( aOriginalFile );
626  backupFileName.SetExt( "bck" );
627 
628  if( backupFileName.FileExists() )
629  wxRemoveFile( backupFileName.GetFullPath() );
630 
631  if( !wxCopyFile( aOriginalFile.GetFullPath(), backupFileName.GetFullPath() ) )
632  {
633  DisplayError( this, wxString::Format( _( "Failed to save backup to \"%s\"" ),
634  backupFileName.GetFullPath() ) );
635  return false;
636  }
637  }
638 
639  return true;
640 }
641 
642 
644 {
645  if( m_my_part && !GetCurLib().IsEmpty() && GetScreen()->IsModify() )
646  m_libMgr->UpdatePart( m_my_part, GetCurLib() ); // UpdatePart() makes a copy
647 }
648 
649 
650 bool LIB_EDIT_FRAME::isCurrentPart( const LIB_ID& aLibId ) const
651 {
652  // This will return the root part of any alias
653  LIB_PART* part = m_libMgr->GetBufferedPart( aLibId.GetLibItemName(), aLibId.GetLibNickname() );
654  // Now we can compare the libId of the current part and the root part
655  return ( part && m_my_part && part->GetLibId() == m_my_part->GetLibId() );
656 }
657 
658 
660 {
662  SetCurLib( wxEmptyString );
663  SetCurPart( nullptr );
667  Refresh();
668 }
669 
670 
671 void LIB_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
672 {
673  SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
674 
676 
677  if( aEnvVarsChanged )
678  SyncLibraries( true );
679 
680  Layout();
681  SendSizeEvent();
682 }
683 
684 
686 {
687  // call my base class
689 
690  // tooltips in toolbars
692 
693  // status bar
694  UpdateMsgPanel();
695 }
696 
697 
699 {
700  SCH_BASE_FRAME::SetScreen( aScreen );
701 }
702 
703 
705 {
712 
713  GetCanvas()->Refresh();
714 }
715 
716 
718 {
719  SyncLibraries( true );
720  RebuildView();
721 }
722 
723 
725 {
726  if( !m_my_part )
727  {
728  return BOX2I( VECTOR2I(-100, -100), VECTOR2I( 200, 200 ) );
729  }
730  else
731  {
732  EDA_RECT boundingBox = m_my_part->Flatten()->GetUnitBoundingBox( m_unit, m_convert );
734  boundingBox.GetHeight() ) );
735  }
736 }
737 
738 
740 {
741  const std::string& payload = mail.GetPayload();
742 
743  switch( mail.Command() )
744  {
745  case MAIL_LIB_EDIT:
746  if( !payload.empty() )
747  {
748  wxString libFileName( payload );
749  wxString libNickname;
750  wxString msg;
751 
752  SYMBOL_LIB_TABLE* libTable = Prj().SchSymbolLibTable();
753  const LIB_TABLE_ROW* libTableRow = libTable->FindRowByURI( libFileName );
754 
755  if( !libTableRow )
756  {
757  msg.Printf( _( "The current configuration does not include the symbol library\n"
758  "\"%s\".\nUse Manage Symbol Libraries to edit the configuration." ),
759  libFileName );
760  DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
761  break;
762  }
763 
764  libNickname = libTableRow->GetNickName();
765 
766  if( !libTable->HasLibrary( libNickname, true ) )
767  {
768  msg.Printf( _( "The library with the nickname \"%s\" is not enabled\n"
769  "in the current configuration. Use Manage Symbol Libraries to\n"
770  "edit the configuration." ), libNickname );
771  DisplayErrorMessage( this, _( "Symbol library not enabled." ), msg );
772  break;
773  }
774 
775  SetCurLib( libNickname );
776 
777  if( m_treePane )
778  {
779  LIB_ID id( libNickname, wxEmptyString );
782  }
783  }
784 
785  break;
786 
787  default:
788  ;
789  }
790 }
791 
792 
794 {
795  // switches currently used canvas ( Cairo / OpenGL):
796  SCH_BASE_FRAME::SwitchCanvas( aCanvasType );
797 
798  // Set options specific to symbol editor (axies are always enabled):
799  GetCanvas()->GetGAL()->SetAxesEnabled( true );
800 }
801 
802 
804 {
805  wxCHECK( m_libMgr, false );
806 
807  return m_libMgr->HasModifications();
808 }
#define TEXT_ANGLE_HORIZ
void SetScreen(BASE_SCREEN *aScreen) override
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:236
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:48
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)
#define DEFAULTPINLENGTH
The default pin number size when creating pins(can be changed in preference menu)
Definition: general.h:64
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
void SaveOneSymbol()
Saves the current symbol to a symbol file.
Definition: symbedit.cpp:143
Class 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:522
EVT_UPDATE_UI(ID_MODEDIT_LOAD_MODULE_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard) EVT_UPDATE_UI(ID_ADD_FOOTPRINT_TO_BOARD
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:213
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
name of datasheet
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:249
wxString GetName() const override
Model changes (required full reload)
Definition: tool_base.h:82
This file is part of the common library.
TOOL_DISPATCHER * m_toolDispatcher
Class LIB_DRAWING_TOOLS.
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:137
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.
ACTIONS * m_actions
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
wxString SchematicLibraryFileWildcard()
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:109
void SetSize(const Vec &size)
Definition: box2.h:210
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).
#define DEFAULT_REPEAT_OFFSET_PIN
the default value (overwritten by the eeschema config)
Definition: general.h:52
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:587
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.
bool m_axesEnabled
Whether or not to draw the coordinate system axes
Library Editor pane with component tree and symbol library table selector.
void OnExportBody(wxCommandEvent &aEvent)
Class 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
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:59
Class TOOL_MANAGER.
Definition: tool_manager.h:50
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
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:220
bool AddLibrary(const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
Adds an existing library.
Definition: lib_manager.h:145
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:126
const BOX2I GetDocumentExtents() const override
int GetUnitCount() const override
For items with units, return the number of units.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxString GetUniqueLibraryName() const
Returns a library name that is not currently in use.
const std::string SchematicLibraryFileExtension
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
const LIB_TABLE_ROW * FindRowByURI(const wxString &aURI)
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
coord_type GetWidth() const
Definition: box2.h:195
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
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:145
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
Define a library symbol object.
Definition of file extensions used in Kicad.
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:175
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)
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:274
bool saveSymbolLibTables(bool aGlobal, bool aProject)
Saves Symbol Library Tables to disk.
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
wxString GetDocFileName() const
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:275
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:58
void SetCurrentPart(const wxString &aPart)
Definition: lib_manager.h:281
void CommonSettingsChanged(bool aEnvVarsChanged) override
Called after the preferences dialog is run.
std::unique_ptr< LIB_PART > Flatten() const
Return a flattened symbol inheritance to the caller.
Class COMMON_CONTROL.
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:204
void SetAxesEnabled(bool aAxesEnabled)
Enables drawing the axes.
#define _(s)
The the schematic editor to refresh the display.
Definition: mail_type.h:46
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
Class EESCHEMA_ACTIONS.
Definition: ee_actions.h:43
Class COMMON_TOOLS.
Definition: common_tools.h:38
void emptyScreen()
Restores the empty editor screen, without any part or library selected.
Class TOOL_DISPATCHER.
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:171
Class to handle modifications to the symbol libraries.
Definition: lib_manager.h:98
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition: lib_tree.cpp:180
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:427
bool backupFile(const wxFileName &aOriginalFile, const wxString &aBackupExt)
Creates a backup copy of a file with requested extension
void SyncLibraries(bool aShowProgress)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
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:186
LIB_PART * GetBufferedPart(const wxString &aAlias, const wxString &aLibrary)
Returns the part copy from the buffer.
The symbol library editor main window.
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:101
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)
Definition: libedit.cpp:873
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.
#define max(a, b)
Definition: auxiliary.h:86
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets a dispatcher that processes events and forwards them to tools.
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
Class EE_POINT_EDITOR.
void SetScreen(BASE_SCREEN *aScreen) override
size_t i
Definition: json11.cpp:649
bool IsAlias() const
void SetOrigin(const Vec &pos)
Definition: box2.h:208
Class 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.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, EDA_BASE_FRAME *aFrame)
Sets the work environment (model, view, view controls and the parent window).
coord_type GetHeight() const
Definition: box2.h:196
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:65
#define DEFAULTPINNAMESIZE
The default library pane width.
Definition: general.h:70
LIB_PART * getTargetPart() const
Returns currently edited part.
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:42
void OnGridSettings(wxCommandEvent &aEvent) override
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
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.
TOOL_MANAGER * m_toolManager
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.
Definition for part library class.
const Vec & GetOrigin() const
Definition: box2.h:191
#define DEFAULTPINNUMSIZE
The default pin name size when creating pins(can be changed in preference menu)
Definition: general.h:67
wxComboBox * m_unitSelectBox
void SetModify()
Definition: base_screen.h:224
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_FIELD * GetField(int aId) const
Return pointer to the requested field.
LIB_TREE_MODEL_ADAPTER::PTR & GetAdapter()
Returns the adapter object that provides the stored data.
Definition: lib_manager.h:269
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 UnitsLocked() const
Check whether part units are interchangeable.
~LIB_EDIT_FRAME() override
void Regenerate()
Updates the component tree
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.
int GetDefaultTextSize()
Default size for text in general.
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferrably centered).
Definition: lib_tree.cpp:169
void OnExitKiCad(wxCommandEvent &event)
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:163
virtual void UpdateMsgPanel()
Redraw the message panel.
ACTION_TOOLBAR * m_drawToolBar