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-2018 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #include <fctsys.h>
32 #include <pgm_base.h>
33 #include <kiface_i.h>
34 #include <kiway_express.h>
35 #include <sch_draw_panel.h>
36 #include <base_screen.h>
37 #include <confirm.h>
38 #include <eda_doc.h>
39 #include <gr_basic.h>
40 #include <sch_edit_frame.h>
41 #include <msgpanel.h>
42 #include <confirm.h>
43 #include <eda_dockart.h>
44 
45 #include <general.h>
46 #include <eeschema_id.h>
47 #include <lib_edit_frame.h>
48 #include <class_library.h>
49 #include <lib_polyline.h>
50 #include <lib_pin.h>
51 
52 #include <lib_manager.h>
54 #include <widgets/lib_tree.h>
55 #include <symbol_lib_table.h>
56 #include <list_operations.h>
57 #include <kicad_device_context.h>
58 #include <hotkeys.h>
59 #include <eeschema_config.h>
60 
64 
66 
67 #include <menus_helpers.h>
68 #include <wx/progdlg.h>
69 #include <tool/context_menu.h>
70 #include <sch_view.h>
71 #include <sch_painter.h>
72 
76 
78 wxSize LIB_EDIT_FRAME:: m_clientSize = wxSize( -1, -1 );
82 
83 // these values are overridden when reading the config
87 
89 
90 
91 BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
92  EVT_CLOSE( LIB_EDIT_FRAME::OnCloseWindow )
93  EVT_SIZE( LIB_EDIT_FRAME::OnSize )
94  EVT_ACTIVATE( LIB_EDIT_FRAME::OnActivate )
95 
96  // Actions
97  EVT_TOOL( ID_LIBEDIT_NEW_LIBRARY, LIB_EDIT_FRAME::OnCreateNewLibrary )
103  EVT_TOOL( ID_LIBEDIT_NEW_PART, LIB_EDIT_FRAME::OnCreateNewPart )
108  EVT_TOOL( ID_LIBEDIT_CUT_PART, LIB_EDIT_FRAME::OnCopyCutPart )
109  EVT_TOOL( ID_LIBEDIT_COPY_PART, LIB_EDIT_FRAME::OnCopyCutPart )
110  EVT_TOOL( ID_LIBEDIT_PASTE_PART, LIB_EDIT_FRAME::OnPasteDuplicatePart )
111  EVT_TOOL( ID_LIBEDIT_DUPLICATE_PART, LIB_EDIT_FRAME::OnPasteDuplicatePart )
112 
113  // Main horizontal toolbar.
114  EVT_TOOL( ID_TO_LIBVIEW, LIB_EDIT_FRAME::OnOpenLibraryViewer )
115  EVT_TOOL( wxID_COPY, LIB_EDIT_FRAME::Process_Special_Functions )
116  EVT_TOOL( wxID_PASTE, LIB_EDIT_FRAME::Process_Special_Functions )
117  EVT_TOOL( wxID_CUT, LIB_EDIT_FRAME::Process_Special_Functions )
118  EVT_TOOL( wxID_UNDO, LIB_EDIT_FRAME::GetComponentFromUndoList )
119  EVT_TOOL( wxID_REDO, LIB_EDIT_FRAME::GetComponentFromRedoList )
120  EVT_TOOL( ID_LIBEDIT_GET_FRAME_EDIT_PART, LIB_EDIT_FRAME::OnEditComponentProperties )
121  EVT_TOOL( ID_LIBEDIT_CHECK_PART, LIB_EDIT_FRAME::OnCheckComponent )
122  EVT_TOOL( ID_DE_MORGAN_NORMAL_BUTT, LIB_EDIT_FRAME::OnSelectBodyStyle )
123  EVT_TOOL( ID_DE_MORGAN_CONVERT_BUTT, LIB_EDIT_FRAME::OnSelectBodyStyle )
124  EVT_TOOL( ID_LIBEDIT_VIEW_DOC, LIB_EDIT_FRAME::OnViewEntryDoc )
125  EVT_TOOL( ID_LIBEDIT_SYNC_PIN_EDIT, LIB_EDIT_FRAME::Process_Special_Functions )
127 
128  EVT_COMBOBOX( ID_LIBEDIT_SELECT_PART_NUMBER, LIB_EDIT_FRAME::OnSelectPart )
129 
130  // Right vertical toolbar.
133  EVT_TOOL( ID_ZOOM_SELECTION, LIB_EDIT_FRAME::OnSelectTool )
135  LIB_EDIT_FRAME::OnSelectTool )
136 
137  // Left vertical toolbar (option toolbar).
140 
141  // menubar commands
142  EVT_MENU( wxID_EXIT, LIB_EDIT_FRAME::CloseWindow )
143  EVT_MENU( ID_LIBEDIT_GEN_PNG_FILE, LIB_EDIT_FRAME::OnPlotCurrentComponent )
144  EVT_MENU( ID_LIBEDIT_GEN_SVG_FILE, LIB_EDIT_FRAME::OnPlotCurrentComponent )
145  EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
146  EVT_MENU( wxID_INDEX, EDA_DRAW_FRAME::GetKicadHelp )
147  EVT_MENU( ID_HELP_GET_INVOLVED, EDA_DRAW_FRAME::GetKicadContribute )
148  EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout )
149  EVT_MENU( ID_GRID_SETTINGS, SCH_BASE_FRAME::OnGridSettings )
150 
151  EVT_MENU( wxID_PREFERENCES, LIB_EDIT_FRAME::OnPreferencesOptions )
152 
153  // Multiple item selection context menu commands.
155 
157 
158  // Context menu events and commands.
161 
164  LIB_EDIT_FRAME::Process_Special_Functions )
165 
167  LIB_EDIT_FRAME::Process_Special_Functions )
168 
170  LIB_EDIT_FRAME::OnOrient )
171 
172  // Update user interface elements.
173  EVT_UPDATE_UI( wxID_PASTE, LIB_EDIT_FRAME::OnUpdatePaste )
174  EVT_UPDATE_UI( ID_LIBEDIT_EXPORT_PART, LIB_EDIT_FRAME::OnUpdateHavePart )
175  EVT_UPDATE_UI( ID_LIBEDIT_SAVE, LIB_EDIT_FRAME::OnUpdateSave )
176  EVT_UPDATE_UI( ID_LIBEDIT_SAVE_AS, LIB_EDIT_FRAME::OnUpdateSaveAs )
177  EVT_UPDATE_UI( ID_LIBEDIT_REVERT, LIB_EDIT_FRAME::OnUpdateRevert )
178  EVT_UPDATE_UI( ID_LIBEDIT_CHECK_PART, LIB_EDIT_FRAME::OnUpdateEditingPart )
179  EVT_UPDATE_UI( ID_LIBEDIT_GET_FRAME_EDIT_PART, LIB_EDIT_FRAME::OnUpdateEditingPart )
180  EVT_UPDATE_UI( wxID_UNDO, LIB_EDIT_FRAME::OnUpdateUndo )
181  EVT_UPDATE_UI( wxID_REDO, LIB_EDIT_FRAME::OnUpdateRedo )
182  EVT_UPDATE_UI( ID_LIBEDIT_SYNC_PIN_EDIT, LIB_EDIT_FRAME::OnUpdateSyncPinEdit )
183  EVT_UPDATE_UI( ID_LIBEDIT_EDIT_PIN_BY_TABLE, LIB_EDIT_FRAME::OnUpdatePinTable )
184  EVT_UPDATE_UI( ID_LIBEDIT_SELECT_PART_NUMBER, LIB_EDIT_FRAME::OnUpdatePartNumber )
185  EVT_UPDATE_UI( ID_DE_MORGAN_NORMAL_BUTT, LIB_EDIT_FRAME::OnUpdateDeMorganNormal )
186  EVT_UPDATE_UI( ID_DE_MORGAN_CONVERT_BUTT, LIB_EDIT_FRAME::OnUpdateDeMorganConvert )
187  EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, LIB_EDIT_FRAME::OnUpdateSelectTool )
188  EVT_UPDATE_UI( ID_ZOOM_SELECTION, LIB_EDIT_FRAME::OnUpdateSelectTool )
189  EVT_UPDATE_UI_RANGE( ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_DELETE_ITEM_BUTT,
190  LIB_EDIT_FRAME::OnUpdateEditingPart )
191  EVT_UPDATE_UI( ID_LIBEDIT_SHOW_ELECTRICAL_TYPE, LIB_EDIT_FRAME::OnUpdateElectricalType )
192  EVT_UPDATE_UI( ID_LIBEDIT_SHOW_HIDE_SEARCH_TREE, LIB_EDIT_FRAME::OnUpdateSearchTreeTool )
193 
194 END_EVENT_TABLE()
195 
196 LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
197  SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_LIB_EDITOR, _( "Library Editor" ),
198  wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, LIB_EDIT_FRAME_NAME )
199 {
200  m_showAxis = true; // true to draw axis
201  SetShowDeMorgan( false );
202  m_drawSpecificConvert = true;
203  m_drawSpecificUnit = false;
204  m_hotkeysDescrList = g_Libedit_Hokeys_Descr;
205  m_syncPinEdit = false;
206  m_repeatPinStep = DEFAULT_REPEAT_OFFSET_PIN;
207  SetShowElectricalType( true );
208  m_FrameSize = ConvertDialogToPixels( wxSize( 500, 350 ) ); // default in case of no prefs
209 
210  m_my_part = NULL;
211  m_tempCopyComponent = NULL;
212  m_treePane = nullptr;
213  m_libMgr = nullptr;
214 
215  // Delayed initialization
216  if( m_textSize == -1 )
217  m_textSize = GetDefaultTextSize();
218 
219  // Initialize grid id to the default value 50 mils:
221 
222  wxIcon icon;
223  icon.CopyFromBitmap( KiBitmap( icon_libedit_xpm ) );
224  SetIcon( icon );
225 
226  LoadSettings( config() );
227 
228  m_dummyScreen = new SCH_SCREEN( aKiway );
229  SetScreen( m_dummyScreen );
230  GetScreen()->m_Center = true;
231  GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
232 
233  SetCrossHairPosition( wxPoint( 0, 0 ) );
234 
235  SetPresetGrid( m_LastGridSizeId );
236 
237  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
238 
239  if( m_canvas )
240  m_canvas->SetEnableBlockCommands( true );
241 
242  m_libMgr = new LIB_MANAGER( *this );
243  SyncLibraries( true );
244  m_treePane = new SYMBOL_TREE_PANE( this, m_libMgr );
245 
246  ReCreateMenuBar();
247  ReCreateHToolbar();
248  ReCreateVToolbar();
249  ReCreateOptToolbar();
250 
251  updateTitle();
252  DisplayCmpDoc();
253  UpdatePartSelectList();
254 
255  m_auimgr.SetManagedWindow( this );
256  m_auimgr.SetArtProvider( new EDA_DOCKART( this ) );
257 
258 
259  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
260  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
261 
262  m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) );
263  m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "ComponentTree" ).Left().Layer(1)
264  .Caption( _( "Libraries" ) ).MinSize( 250, -1 ).Resizable() );
265  m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ).Right().Layer(1) );
266 
267  m_auimgr.AddPane( m_canvas->GetWindow(), wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
268 
269  m_auimgr.Update();
270 
271  Raise();
272  Show( true );
273 
274  Bind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnConfigurePaths, this,
276 
277  Bind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnEditSymbolLibTable, this,
279 
280  wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, ID_ZOOM_PAGE );
281  wxPostEvent( this, evt );
282 
283  SyncView();
284  GetGalCanvas()->GetViewControls()->SetSnapping( true );
285  GetGalCanvas()->GetView()->UseDrawPriority( true );
286  GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
287  GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
288 
289  // Set the working/draw area size to display a symbol to a reasonable value:
290  // A 600mm x 600mm with a origin at the area center looks like a large working area
291  double max_size_x = Millimeter2iu( 600 );
292  double max_size_y = Millimeter2iu( 600 );
293  BOX2D bbox;
294  bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
295  bbox.SetSize( max_size_x, max_size_y );
296  GetCanvas()->GetView()->SetBoundary( bbox );
297 }
298 
299 
301 {
302  Unbind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnEditSymbolLibTable, this,
304 
305  // current screen is destroyed in EDA_DRAW_FRAME
307 
308  m_lastDrawItem = NULL;
310 
311  delete m_tempCopyComponent;
312  delete m_libMgr;
313  delete m_my_part;
314 }
315 
316 
317 void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
318 {
319  if( saveAllLibraries( true ) )
320  Destroy();
321  else
322  Event.Veto();
323 }
324 
325 
327 {
328  LIB_PART* part = GetCurPart();
329  double defaultLibraryZoom = 7.33;
330 
331  if( !part )
332  {
333  SetScrollCenterPosition( wxPoint( 0, 0 ) );
334  return defaultLibraryZoom;
335  }
336 
338 
339  double sizeX = (double) boundingBox.GetWidth();
340  double sizeY = (double) boundingBox.GetHeight();
341  wxPoint centre = boundingBox.Centre();
342 
343  // Reserve a 20% margin around component bounding box.
344  double margin_scale_factor = 1.2;
345 
346  return bestZoom( sizeX, sizeY, margin_scale_factor, centre);
347 }
348 
349 
351 {
352  if( m_partSelectBox == NULL )
353  return;
354 
355  if( m_partSelectBox->GetCount() != 0 )
356  m_partSelectBox->Clear();
357 
358  LIB_PART* part = GetCurPart();
359 
360  if( !part || part->GetUnitCount() <= 1 )
361  {
362  m_unit = 1;
363  m_partSelectBox->Append( wxEmptyString );
364  }
365  else
366  {
367  for( int i = 0; i < part->GetUnitCount(); i++ )
368  {
369  wxString sub = LIB_PART::SubReference( i+1, false );
370  wxString unit = wxString::Format( _( "Unit %s" ), GetChars( sub ) );
371  m_partSelectBox->Append( unit );
372  }
373  }
374 
375  // Ensure the current selected unit is compatible with
376  // the number of units of the current part:
377  if( part && part->GetUnitCount() < m_unit )
378  m_unit = 1;
379 
380  m_partSelectBox->SetSelection( ( m_unit > 0 ) ? m_unit - 1 : 0 );
381 }
382 
383 
384 void LIB_EDIT_FRAME::OnShowElectricalType( wxCommandEvent& event )
385 {
387 
388  // Update canvas
391  GetCanvas()->Refresh();
392 }
393 
394 
395 void LIB_EDIT_FRAME::OnToggleSearchTree( wxCommandEvent& event )
396 {
397  auto& treePane = m_auimgr.GetPane( m_treePane );
398  treePane.Show( !IsSearchTreeShown() );
399  m_auimgr.Update();
400 }
401 
402 
403 void LIB_EDIT_FRAME::OnEditSymbolLibTable( wxCommandEvent& aEvent )
404 {
405  m_libMgr->GetAdapter()->Freeze();
406 
408  SyncLibraries( true );
409 
410  m_libMgr->GetAdapter()->Thaw();
411 }
412 
413 
415 {
416  return m_auimgr.GetPane( m_treePane ).IsShown();
417 }
418 
419 
421 {
423 }
424 
425 
426 void LIB_EDIT_FRAME::OnUpdateSelectTool( wxUpdateUIEvent& aEvent )
427 {
428  if( aEvent.GetEventObject() == m_drawToolBar || aEvent.GetEventObject() == m_mainToolBar )
429  aEvent.Check( GetToolId() == aEvent.GetId() );
430 }
431 
432 
433 void LIB_EDIT_FRAME::OnUpdateElectricalType( wxUpdateUIEvent& aEvent )
434 {
435  aEvent.Check( GetShowElectricalType() );
436 }
437 
438 
439 void LIB_EDIT_FRAME::OnUpdateSearchTreeTool( wxUpdateUIEvent& aEvent )
440 {
441  aEvent.Check( IsSearchTreeShown() );
442 }
443 
444 
445 void LIB_EDIT_FRAME::OnUpdateSave( wxUpdateUIEvent& aEvent )
446 {
447  LIB_ID libId = getTargetLibId();
448  const wxString& libName = libId.GetLibNickname();
449  const wxString& partName = libId.GetLibItemName();
450  bool readOnly = libName.IsEmpty() || m_libMgr->IsLibraryReadOnly( libName );
451 
452  if( partName.IsEmpty() )
453  aEvent.Enable( !readOnly && m_libMgr->IsLibraryModified( libName ) );
454  else
455  aEvent.Enable( !readOnly && m_libMgr->IsPartModified( partName, libName ) );
456 }
457 
458 
459 void LIB_EDIT_FRAME::OnUpdateSaveAs( wxUpdateUIEvent& aEvent )
460 {
461  LIB_ID libId = getTargetLibId();
462  const wxString& libName = libId.GetLibNickname();
463  const wxString& partName = libId.GetLibItemName();
464 
465  aEvent.Enable( !libName.IsEmpty() || !partName.IsEmpty() );
466 }
467 
468 
469 void LIB_EDIT_FRAME::OnUpdateRevert( wxUpdateUIEvent& aEvent )
470 {
471  LIB_ID libId = getTargetLibId();
472  const wxString& libName = libId.GetLibNickname();
473  const wxString& partName = libId.GetLibItemName();
474 
475  if( partName.IsEmpty() )
476  aEvent.Enable( !libName.IsEmpty() && m_libMgr->IsLibraryModified( libName ) );
477  else
478  aEvent.Enable( !libName.IsEmpty() && m_libMgr->IsPartModified( partName, libName ) );
479 }
480 
481 
482 void LIB_EDIT_FRAME::OnUpdateHavePart( wxUpdateUIEvent& aEvent )
483 {
484  aEvent.Enable( getTargetLibId().IsValid() );
485 }
486 
487 
488 void LIB_EDIT_FRAME::OnUpdateEditingPart( wxUpdateUIEvent& aEvent )
489 {
490  LIB_PART* part = GetCurPart();
491 
492  aEvent.Enable( part != NULL );
493 
494  if( part && aEvent.GetEventObject() == m_drawToolBar )
495  aEvent.Check( GetToolId() == aEvent.GetId() );
496 }
497 
498 
499 void LIB_EDIT_FRAME::OnUpdatePaste( wxUpdateUIEvent& event )
500 {
501  event.Enable( m_clipboard.GetCount() > 0 );
502 }
503 
504 
505 void LIB_EDIT_FRAME::OnUpdateUndo( wxUpdateUIEvent& event )
506 {
507  event.Enable( GetCurPart() && GetScreen() &&
508  GetScreen()->GetUndoCommandCount() != 0 && !IsEditingDrawItem() );
509 }
510 
511 
512 void LIB_EDIT_FRAME::OnUpdateRedo( wxUpdateUIEvent& event )
513 {
514  event.Enable( GetCurPart() && GetScreen() &&
515  GetScreen()->GetRedoCommandCount() != 0 && !IsEditingDrawItem() );
516 }
517 
518 
519 void LIB_EDIT_FRAME::OnUpdateSyncPinEdit( wxUpdateUIEvent& event )
520 {
521  LIB_PART* part = GetCurPart();
522  event.Enable( part && part->IsMulti() && !part->UnitsLocked() );
523  event.Check( m_syncPinEdit );
524 }
525 
526 
527 void LIB_EDIT_FRAME::OnUpdatePinTable( wxUpdateUIEvent& event )
528 {
529  LIB_PART* part = GetCurPart();
530  event.Enable( part != NULL );
531 }
532 
533 
534 void LIB_EDIT_FRAME::OnUpdatePartNumber( wxUpdateUIEvent& event )
535 {
536  if( m_partSelectBox == NULL )
537  return;
538 
539  LIB_PART* part = GetCurPart();
540 
541  // Using the typical event.Enable() call doesn't seem to work with wxGTK
542  // so use the pointer to alias combobox to directly enable or disable.
543  m_partSelectBox->Enable( part && part->GetUnitCount() > 1 );
544 }
545 
546 
547 void LIB_EDIT_FRAME::OnUpdateDeMorganNormal( wxUpdateUIEvent& event )
548 {
549  if( m_mainToolBar == NULL )
550  return;
551 
552  LIB_PART* part = GetCurPart();
553 
554  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
555  event.Check( m_convert <= 1 );
556 }
557 
558 
559 void LIB_EDIT_FRAME::OnUpdateDeMorganConvert( wxUpdateUIEvent& event )
560 {
561  if( m_mainToolBar == NULL )
562  return;
563 
564  LIB_PART* part = GetCurPart();
565 
566  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
567  event.Check( m_convert > 1 );
568 }
569 
570 
571 void LIB_EDIT_FRAME::OnSelectPart( wxCommandEvent& event )
572 {
573  int i = event.GetSelection();
574 
575  if( ( i == wxNOT_FOUND ) || ( ( i + 1 ) == m_unit ) )
576  return;
577 
578  m_lastDrawItem = NULL;
579  m_unit = i + 1;
580 
581  RebuildView();
582  DisplayCmpDoc();
583 }
584 
585 
586 void LIB_EDIT_FRAME::OnViewEntryDoc( wxCommandEvent& event )
587 {
588  LIB_PART* part = GetCurPart();
589 
590  if( !part )
591  return;
592 
593  wxString filename;
594 
595  if( part->GetAliasCount() > 1 )
596  {
597  CONTEXT_MENU popup;
598  wxString msg;
599  int id = 0;
600 
601  for( LIB_ALIAS* alias : part->GetAliases() )
602  {
603  msg.Printf( wxT( "%s (%s)" ), alias->GetName(), alias->GetDocFileName() );
604  popup.Append( id++, msg );
605  }
606 
607  PopupMenu( &popup );
608 
609  if( popup.GetSelected() >= 0 )
610  filename = part->GetAlias( (unsigned) popup.GetSelected() )->GetDocFileName();
611  }
612  else
613  filename = part->GetAlias( 0 )->GetDocFileName();
614 
615  if( !filename.IsEmpty() && filename != wxT( "~" ) )
616  {
617  SEARCH_STACK* lib_search = Prj().SchSearchS();
618 
619  GetAssociatedDocument( this, filename, lib_search );
620  }
621 }
622 
623 
624 void LIB_EDIT_FRAME::OnSelectBodyStyle( wxCommandEvent& event )
625 {
626  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
627 
628  if( event.GetId() == ID_DE_MORGAN_NORMAL_BUTT )
629  m_convert = 1;
630  else
631  m_convert = 2;
632 
633  m_lastDrawItem = NULL;
634 
635  RebuildView();
636 }
637 
638 
639 void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
640 {
641  int id = event.GetId();
642  wxPoint pos;
643  SCH_SCREEN* screen = GetScreen();
645  LIB_ITEM* item = screen->GetCurLibItem();
646 
648 
649  wxGetMousePosition( &pos.x, &pos.y );
650  pos.y += 20;
651 
652  switch( id ) // Stop placement commands before handling new command.
653  {
654  case wxID_COPY:
655  case ID_POPUP_COPY_BLOCK:
656  case wxID_CUT:
657  case ID_POPUP_CUT_BLOCK:
659  case ID_LIBEDIT_EDIT_PIN:
665  case ID_POPUP_ZOOM_BLOCK:
674  break;
675 
677  if( m_canvas->IsMouseCaptured() )
679  else
680  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
681  break;
682 
685  break;
686 
687  default:
688  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor(),
689  wxEmptyString );
690  break;
691  }
692 
693  switch( id )
694  {
696  break;
697 
700  break;
701 
704  if( item )
705  {
706  EndDrawGraphicItem( nullptr );
707  }
708  break;
709 
711  if( item )
712  {
714 
715  switch( item->Type() )
716  {
717  case LIB_ARC_T:
718  case LIB_CIRCLE_T:
719  case LIB_RECTANGLE_T:
720  case LIB_POLYLINE_T:
721  EditGraphicSymbol( nullptr, item );
722  break;
723 
724  case LIB_TEXT_T:
725  EditSymbolText( nullptr, item );
726  break;
727 
728  default:
729  ;
730  }
731 
732  m_canvas->CrossHairOn( );
733  }
734  break;
735 
737  {
738  // Delete the last created segment, while creating a polyline draw item
739  if( item == NULL )
740  break;
741 
743  STATUS_FLAGS oldFlags = item->GetFlags();
744  item->ClearFlags();
745  /* item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
746  DefaultTransform );
747  ( (LIB_POLYLINE*) item )->DeleteSegment( GetCrossHairPosition( true ) );
748  item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
749  DefaultTransform );*/
750  item->SetFlags( oldFlags );
751  m_lastDrawItem = NULL;
752  }
753  break;
754 
756  if( item )
757  deleteItem( nullptr, item );
758 
759  break;
760 
762  if( item == NULL )
763  break;
764 
765  if( item->Type() == LIB_PIN_T )
766  {
767  StartMovePin( item );
768  }
769  else
770  {
771  StartMoveDrawSymbol( nullptr, item );
772  }
773  break;
774 
776 
777  if( item == NULL )
778  break;
779 
781  if( item->Type() == LIB_RECTANGLE_T
782  || item->Type() == LIB_CIRCLE_T
783  || item->Type() == LIB_POLYLINE_T
784  || item->Type() == LIB_ARC_T
785  )
786  {
787  StartModifyDrawSymbol( nullptr, item );
788  }
789 
790  break;
791 
793  if( item == NULL )
794  break;
795 
796  m_canvas->CrossHairOff( nullptr );
797 
798  if( item->Type() == LIB_FIELD_T )
799  {
800  EditField( (LIB_FIELD*) item );
801  }
802 
804  m_canvas->CrossHairOn( );
805  break;
806 
810  {
811  if( !item || item->Type() != LIB_PIN_T )
812  break;
813 
814  LIB_PART* part = GetCurPart();
815 
816  SaveCopyInUndoList( part );
817 
818  GlobalSetPins( (LIB_PIN*) item, id );
820  }
821  break;
822 
823  case ID_POPUP_ZOOM_BLOCK:
824  m_canvas->SetAutoPanRequest( false );
825  block.SetCommand( BLOCK_ZOOM );
826  HandleBlockEnd( nullptr );
827  break;
828 
830  m_canvas->SetAutoPanRequest( false );
831  block.SetCommand( BLOCK_DELETE );
833  HandleBlockEnd( nullptr );
834  break;
835 
837  m_canvas->SetAutoPanRequest( false );
838  block.SetCommand( BLOCK_DUPLICATE );
840  HandleBlockEnd( nullptr );
841  break;
842 
844  m_canvas->SetAutoPanRequest( false );
847  HandleBlockEnd( nullptr );
848  break;
849 
852  OnOrient( event );
853  break;
854 
856  OnRotate( event );
857  break;
858 
860  m_canvas->SetAutoPanRequest( false );
862  HandleBlockPlace( nullptr );
863  break;
864 
865  case wxID_COPY:
866  case ID_POPUP_COPY_BLOCK:
867  block.SetCommand( BLOCK_COPY );
868  block.SetMessageBlock( this );
869  HandleBlockEnd( nullptr );
870  break;
871 
872  case wxID_PASTE:
875  break;
876 
877  case wxID_CUT:
878  case ID_POPUP_CUT_BLOCK:
879  if( block.GetCommand() != BLOCK_MOVE )
880  break;
881 
882  block.SetCommand( BLOCK_CUT );
883  block.SetMessageBlock( this );
884  HandleBlockEnd( nullptr );
885  break;
886 
887  default:
888  wxFAIL_MSG( "LIB_EDIT_FRAME::Process_Special_Functions error" );
889  break;
890  }
891 
892  m_canvas->SetIgnoreMouseEvents( false );
893 
894  if( GetToolId() == ID_NO_TOOL_SELECTED )
895  m_lastDrawItem = NULL;
896 }
897 
898 
899 void LIB_EDIT_FRAME::OnActivate( wxActivateEvent& event )
900 {
902 }
903 
904 
906 {
907  wxString libNickname = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_LIB );
908 
909  if( !libNickname.empty() )
910  {
911  if( !Prj().SchSymbolLibTable()->HasLibrary( libNickname ) )
912  {
913  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
914  libNickname = wxEmptyString;
915  }
916  }
917 
918  return libNickname;
919 }
920 
921 
922 wxString LIB_EDIT_FRAME::SetCurLib( const wxString& aLibNickname )
923 {
924  wxString old = GetCurLib();
925 
926  if( aLibNickname.empty() || !Prj().SchSymbolLibTable()->HasLibrary( aLibNickname ) )
927  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
928  else
929  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, aLibNickname );
930 
931  m_libMgr->SetCurrentLib( aLibNickname );
932 
933  return old;
934 }
935 
936 
938 {
939  if( !aPart && !m_my_part )
940  return;
941 
942  GetScreen()->SetCurItem( nullptr );
943 
944  if( m_my_part != aPart )
945  {
946  if( m_my_part )
947  delete m_my_part;
948 
949  m_my_part = aPart;
950  }
951 
952  // select the current component in the tree widget
953  if( aPart )
954  m_treePane->GetLibTree()->SelectLibId( aPart->GetLibId() );
955 
956  wxString partName = aPart ? aPart->GetName() : wxString();
957  m_libMgr->SetCurrentPart( partName );
958 
959  // retain in case this wxFrame is re-opened later on the same PROJECT
961 
962  // Ensure synchronized pin edit can be enabled only symbols with interchangeable units
963  m_syncPinEdit = aPart && aPart->IsMulti() && !aPart->UnitsLocked();
964 
965  RebuildView();
966 }
967 
968 
970 {
971  delete m_tempCopyComponent;
972 
973  if( LIB_PART* part = GetCurPart() )
974  // clone it and own the clone.
975  m_tempCopyComponent = new LIB_PART( *part );
976  else
977  // clear it, there was no CurPart
978  m_tempCopyComponent = NULL;
979 }
980 
981 
983 {
984  if( m_tempCopyComponent )
985  {
986  // transfer ownership to CurPart
988  m_tempCopyComponent = NULL;
989  }
990 }
991 
992 
994 {
995  delete m_tempCopyComponent;
996  m_tempCopyComponent = NULL;
997 }
998 
999 
1000 void LIB_EDIT_FRAME::EditSymbolText( wxDC* DC, LIB_ITEM* DrawItem )
1001 {
1002  if ( ( DrawItem == NULL ) || ( DrawItem->Type() != LIB_TEXT_T ) )
1003  return;
1004 
1005  // Deleting old text
1006  if( DC && !DrawItem->InEditMode() )
1007  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
1008  DefaultTransform );
1009 
1010  DIALOG_LIB_EDIT_TEXT dlg( this, (LIB_TEXT*) DrawItem );
1011 
1012  if( dlg.ShowModal() != wxID_OK )
1013  return;
1014 
1015  GetCanvas()->GetView()->Update( DrawItem );
1016  GetCanvas()->Refresh();
1017  OnModify();
1018 
1019  // Display new text
1020  if( DC && !DrawItem->InEditMode() )
1021  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, GR_DEFAULT_DRAWMODE,
1022  NULL, DefaultTransform );
1023 }
1024 
1025 
1026 void LIB_EDIT_FRAME::OnEditComponentProperties( wxCommandEvent& event )
1027 {
1028  bool partLocked = GetCurPart()->UnitsLocked();
1029  wxString oldName = GetCurPart()->GetName();
1030 
1031  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
1032 
1033  if( GetDrawItem() && GetDrawItem()->Type() == LIB_FIELD_T )
1034  SetDrawItem( nullptr ); // selected LIB_FIELD might be deleted
1035 
1037 
1038  // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
1039  // frame. Therefore this dialog as a modal frame parent, MUST be run under
1040  // quasimodal mode for the quasimodal frame support to work. So don't use
1041  // the QUASIMODAL macros here.
1042  if( dlg.ShowQuasiModal() != wxID_OK )
1043  return;
1044 
1045  // if m_UnitSelectionLocked has changed, set some edit options or defaults
1046  // to the best value
1047  if( partLocked != GetCurPart()->UnitsLocked() )
1048  {
1049  // Enable synchronized pin edit mode for symbols with interchangeable units
1051  // also set default edit options to the better value
1052  // Usually if units are locked, graphic items are specific to each unit
1053  // and if units are interchangeable, graphic items are common to units
1055  }
1056 
1057  if( oldName != GetCurPart()->GetName() )
1059  else
1061 
1063  updateTitle();
1064  DisplayCmpDoc();
1065 
1066  RebuildView();
1067  GetCanvas()->Refresh();
1068  OnModify();
1069 }
1070 
1071 
1072 void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
1073 {
1074  int id = aEvent.GetId();
1075  int lastToolID = GetToolId();
1076 
1078  m_lastDrawItem = NULL;
1079 
1080  // Stop the current command and deselect the current tool.
1081  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
1082 
1083  LIB_PART* part = GetCurPart();
1084 
1085  switch( id )
1086  {
1087  case ID_NO_TOOL_SELECTED:
1088  SetToolID( id, GetGalCanvas()->GetDefaultCursor(), wxEmptyString );
1089  break;
1090 
1092  case ID_ZOOM_SELECTION:
1093  // This tool is located on the main toolbar: switch it on or off on click on it
1094  if( lastToolID != ID_ZOOM_SELECTION )
1095  SetToolID( ID_ZOOM_SELECTION, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) );
1096  else
1098  break;
1099 
1100  case ID_LIBEDIT_PIN_BUTT:
1101  if( part )
1102  {
1103  SetToolID( id, wxCURSOR_PENCIL, _( "Add pin" ) );
1104  }
1105  else
1106  {
1107  SetToolID( id, wxCURSOR_ARROW, _( "Set pin options" ) );
1108 
1109  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
1110 
1111  cmd.SetId( ID_LIBEDIT_EDIT_PIN );
1112  GetEventHandler()->ProcessEvent( cmd );
1114  }
1115  break;
1116 
1118  SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) );
1119  break;
1120 
1122  SetToolID( id, wxCURSOR_PENCIL, _( "Add rectangle" ) );
1123  break;
1124 
1126  SetToolID( id, wxCURSOR_PENCIL, _( "Add circle" ) );
1127  break;
1128 
1130  SetToolID( id, wxCURSOR_PENCIL, _( "Add arc" ) );
1131  break;
1132 
1134  SetToolID( id, wxCURSOR_PENCIL, _( "Add line" ) );
1135  break;
1136 
1138  SetToolID( id, wxCURSOR_HAND, _( "Set anchor position" ) );
1139  break;
1140 
1142  SetToolID( id, GetGalCanvas()->GetDefaultCursor(), _( "Import" ) );
1143  LoadOneSymbol();
1145  break;
1146 
1148  SetToolID( id, GetGalCanvas()->GetDefaultCursor(), _( "Export" ) );
1149  SaveOneSymbol();
1151  break;
1152 
1154  if( !part )
1155  {
1156  wxBell();
1157  break;
1158  }
1159 
1160  SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
1161  break;
1162 
1163  default:
1164  break;
1165  }
1166 
1167  m_canvas->SetIgnoreMouseEvents( false );
1168 }
1169 
1170 
1171 void LIB_EDIT_FRAME::OnRotate( wxCommandEvent& aEvent )
1172 {
1173  LIB_PART* part = GetCurPart();
1175  LIB_ITEM* item = GetDrawItem();
1176 
1177  // Allows block rotate operation on hot key.
1178  if( block.GetState() != STATE_NO_BLOCK )
1179  {
1180  // Compute the rotation center and put it on grid:
1181  wxPoint rotationPoint = block.Centre();
1182  rotationPoint = GetNearestGridPosition( rotationPoint );
1183 
1184  // The Y axis orientation is bottom to top for symbol items.
1185  // so change the Y coord value of the rotation center
1186  rotationPoint.y = -rotationPoint.y;
1187 
1188  if( block.AppendUndo() )
1189  ; // UR_LIBEDIT saves entire state, so no need to append anything more
1190  else
1191  {
1192  SaveCopyInUndoList( part, UR_LIBEDIT );
1193  block.SetAppendUndo();
1194  }
1195 
1196  for( unsigned ii = 0; ii < block.GetCount(); ii++ )
1197  {
1198  item = static_cast<LIB_ITEM*>( block.GetItem( ii ) );
1199  item->Rotate( rotationPoint );
1200  }
1201 
1202  GetCanvas()->CallMouseCapture( nullptr, wxDefaultPosition, false );
1203  GetCanvas()->Refresh();
1204  }
1205  else if( item )
1206  {
1207  wxPoint rotationPoint = item->GetPosition();
1208 
1209  if( !item->InEditMode() )
1210  SaveCopyInUndoList( part, UR_LIBEDIT );
1211 
1212  item->Rotate( rotationPoint );
1213 
1214  if( item->InEditMode() )
1215  GetCanvas()->CallMouseCapture( nullptr, wxDefaultPosition, false );
1216  else
1217  GetCanvas()->GetView()->Update( item );
1218  GetCanvas()->Refresh();
1219  OnModify();
1220 
1221  if( !item->InEditMode() )
1222  item->ClearFlags();
1223 
1224  if( GetToolId() == ID_NO_TOOL_SELECTED )
1225  m_lastDrawItem = NULL;
1226  }
1227 }
1228 
1229 
1230 void LIB_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent )
1231 {
1232  LIB_PART* part = GetCurPart();
1234  LIB_ITEM* item = GetDrawItem();
1235 
1236  // Allows block rotate operation on hot key.
1237  if( block.GetState() != STATE_NO_BLOCK )
1238  {
1239  // Compute the mirror center and put it on grid.
1240  wxPoint mirrorPoint = block.Centre();
1241  mirrorPoint = GetNearestGridPosition( mirrorPoint );
1242 
1243  // The Y axis orientation is bottom to top for symbol items.
1244  // so change the Y coord value of the rotation center
1245  mirrorPoint.y = -mirrorPoint.y;
1246 
1247  if( block.AppendUndo() )
1248  ; // UR_LIBEDIT saves entire state, so no need to append anything more
1249  else
1250  {
1251  SaveCopyInUndoList( part, UR_LIBEDIT );
1252  block.SetAppendUndo();
1253  }
1254 
1255  for( unsigned ii = 0; ii < block.GetCount(); ii++ )
1256  {
1257  item = static_cast<LIB_ITEM*>( block.GetItem( ii ) );
1258 
1259  if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y || aEvent.GetId() == ID_POPUP_MIRROR_Y_BLOCK )
1260  item->MirrorHorizontal( mirrorPoint );
1261  else
1262  item->MirrorVertical( mirrorPoint );
1263  }
1264 
1265  m_canvas->CallMouseCapture( nullptr, wxDefaultPosition, false );
1266  GetCanvas()->Refresh();
1267  }
1268  else if( item )
1269  {
1270  wxPoint mirrorPoint = item->GetPosition();
1271  mirrorPoint.y = -mirrorPoint.y;
1272 
1273  if( !item->InEditMode() )
1274  SaveCopyInUndoList( part, UR_LIBEDIT );
1275 
1276  if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y || aEvent.GetId() == ID_POPUP_MIRROR_Y_BLOCK )
1277  item->MirrorHorizontal( mirrorPoint );
1278  else
1279  item->MirrorVertical( mirrorPoint );
1280 
1281  if( item->InEditMode() )
1282  m_canvas->CallMouseCapture( nullptr, wxDefaultPosition, false );
1283  else
1284  GetCanvas()->GetView()->Update( item );
1285  GetCanvas()->Refresh();
1286  OnModify();
1287 
1288  if( !item->InEditMode() )
1289  item->ClearFlags();
1290 
1291  if( GetToolId() == ID_NO_TOOL_SELECTED )
1292  m_lastDrawItem = NULL;
1293  }
1294 }
1295 
1296 
1298  const KICAD_T aFilterList[] )
1299 {
1300  wxPoint pos;
1301  LIB_PART* part = GetCurPart();
1302 
1303  if( !part )
1304  return NULL;
1305 
1306  LIB_ITEM* item = locateItem( aPosition, aFilterList );
1307 
1308  // If the user aborted the clarification context menu, don't show it again at the
1309  // grid position.
1310  if( !item && m_canvas->GetAbortRequest() )
1311  return NULL;
1312 
1313  pos = GetNearestGridPosition( aPosition );
1314 
1315  if( item == NULL && aPosition != pos )
1316  item = locateItem( pos, aFilterList );
1317 
1318  return item;
1319 }
1320 
1321 
1322 LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aFilterList[] )
1323 {
1324  LIB_PART* part = GetCurPart();
1325 
1326  if( !part )
1327  return NULL;
1328 
1329  LIB_ITEM* item = NULL;
1330 
1331  m_collectedItems.Collect( part->GetDrawItems(), aFilterList, aPosition,
1332  m_unit, m_convert );
1333 
1334  if( m_collectedItems.GetCount() == 0 )
1335  {
1336  ClearMsgPanel();
1337  }
1338  else if( m_collectedItems.GetCount() == 1 )
1339  {
1340  item = m_collectedItems[0];
1341  }
1342  else
1343  {
1344  if( item == NULL )
1345  {
1346  wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS,
1347  "Select item clarification context menu size limit exceeded." );
1348 
1349  wxMenu selectMenu;
1350  AddMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ),
1351  KiBitmap( info_xpm ) );
1352 
1353  selectMenu.AppendSeparator();
1354 
1355  for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ )
1356  {
1357  wxString text = m_collectedItems[i]->GetSelectMenuText( m_UserUnits );
1358  BITMAP_DEF xpm = m_collectedItems[i]->GetMenuImage();
1359 
1360  AddMenuItem( &selectMenu, ID_SELECT_ITEM_START + i, text, KiBitmap( xpm ) );
1361  }
1362 
1363  // Set to NULL in case user aborts the clarification context menu.
1364  SetDrawItem( NULL );
1365  m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected
1366  PopupMenu( &selectMenu );
1368  item = GetDrawItem();
1369  }
1370  }
1371 
1372  if( item )
1373  {
1374  MSG_PANEL_ITEMS items;
1375  item->GetMsgPanelInfo( m_UserUnits, items );
1376  SetMsgPanel( items );
1377  }
1378  else
1379  {
1380  ClearMsgPanel();
1381  }
1382 
1383  return item;
1384 }
1385 
1386 
1387 void LIB_EDIT_FRAME::deleteItem( wxDC* aDC, LIB_ITEM* aItem )
1388 {
1389  if( !aItem )
1390  return;
1391 
1392  m_canvas->CrossHairOff( aDC );
1393 
1394  LIB_PART* part = GetCurPart();
1395 
1396  SaveCopyInUndoList( part );
1397 
1398  if( aItem->Type() == LIB_PIN_T )
1399  {
1400  LIB_PIN* pin = static_cast<LIB_PIN*>( aItem );
1401  wxPoint pos = pin->GetPosition();
1402 
1403  part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC );
1404 
1405  // when pin editing is synchronized, all pins of the same body style are removed:
1406  if( SynchronizePins() )
1407  {
1408  int curr_convert = pin->GetConvert();
1409  LIB_PIN* next_pin = part->GetNextPin();
1410 
1411  while( next_pin != NULL )
1412  {
1413  pin = next_pin;
1414  next_pin = part->GetNextPin( pin );
1415 
1416  if( pin->GetPosition() != pos )
1417  continue;
1418 
1419  if( pin->GetConvert() != curr_convert )
1420  continue;
1421 
1422  part->RemoveDrawItem( pin );
1423  }
1424  }
1425  }
1426  else
1427  {
1428  if( m_canvas->IsMouseCaptured() )
1429  m_canvas->CallEndMouseCapture( aDC );
1430  else
1431  part->RemoveDrawItem( aItem, m_canvas, aDC );
1432  }
1433 
1434  SetDrawItem( NULL );
1435  m_lastDrawItem = NULL;
1436  OnModify();
1437  m_canvas->CrossHairOn( aDC );
1438 
1439  RebuildView();
1440  GetCanvas()->Refresh();
1441 }
1442 
1443 
1445 {
1446  GetScreen()->SetModify();
1447  storeCurrentPart();
1448 
1449  m_treePane->GetLibTree()->Refresh();
1450 }
1451 
1452 
1453 void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent )
1454 {
1455  int id = aEvent.GetId();
1456  int index = id - ID_SELECT_ITEM_START;
1457 
1458  if( (id >= ID_SELECT_ITEM_START && id <= ID_SELECT_ITEM_END)
1459  && (index >= 0 && index < m_collectedItems.GetCount()) )
1460  {
1461  LIB_ITEM* item = m_collectedItems[index];
1462  m_canvas->SetAbortRequest( false );
1463  SetDrawItem( item );
1464  }
1465 }
1466 
1467 
1468 void LIB_EDIT_FRAME::OnOpenPinTable( wxCommandEvent& aEvent )
1469 {
1470  LIB_PART* part = GetCurPart();
1471  SaveCopyInUndoList( part );
1472  SetDrawItem( nullptr );
1473 
1474  DIALOG_LIB_EDIT_PIN_TABLE dlg( this, part );
1475 
1476  if( dlg.ShowModal() == wxID_CANCEL )
1477  return;
1478 
1479  RebuildView();
1480  GetCanvas()->Refresh();
1481  OnModify();
1482 }
1483 
1484 
1486 {
1487  LIB_PART* part = GetCurPart();
1488 
1489  return m_syncPinEdit && part && part->IsMulti() && !part->UnitsLocked();
1490 }
1491 
1492 
1494 {
1495  // There may be no parent window so use KIWAY message to refresh the schematic editor
1496  // in case any symbols have changed.
1497  Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_REFRESH, std::string( "" ), this );
1498 }
1499 
1500 
1501 bool LIB_EDIT_FRAME::addLibraryFile( bool aCreateNew )
1502 {
1503  wxFileName fn = m_libMgr->GetUniqueLibraryName();
1504 
1505  if( !LibraryFileBrowser( !aCreateNew, fn,
1507  false ) )
1508  {
1509  return false;
1510  }
1511 
1512  wxString libName = fn.GetName();
1513 
1514  if( libName.IsEmpty() )
1515  return false;
1516 
1517  if( m_libMgr->LibraryExists( libName ) )
1518  {
1519  DisplayError( this, wxString::Format( _( "Library \"%s\" already exists" ), libName ) );
1520  return false;
1521  }
1522 
1523  // Select the target library table (global/project)
1524  SYMBOL_LIB_TABLE* libTable = selectSymLibTable();
1525 
1526  if( !libTable )
1527  return false;
1528 
1529  if( aCreateNew )
1530  {
1531  if( !m_libMgr->CreateLibrary( fn.GetFullPath(), libTable ) )
1532  {
1533  DisplayError( this, _( "Could not create the library file. Check write permission." ) );
1534  return false;
1535  }
1536  }
1537  else
1538  {
1539  if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
1540  {
1541  DisplayError( this, _( "Could not open the library file." ) );
1542  return false;
1543  }
1544  }
1545 
1546  bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
1547  saveSymbolLibTables( globalTable, !globalTable );
1548 
1549  return true;
1550 }
1551 
1552 
1554 {
1555  LIB_ALIAS* alias = nullptr;
1556 
1557  if( m_treePane->GetLibTree()->IsMenuActive() )
1558  {
1560  alias = m_libMgr->GetAlias( libId.GetLibItemName(), libId.GetLibNickname() );
1561  }
1562  else if( LIB_PART* part = GetCurPart() )
1563  {
1564  alias = part->GetAlias( 0 );
1565  }
1566 
1567  return alias ? alias->GetPart() : nullptr;
1568 }
1569 
1570 
1572 {
1574  wxString nickname = id.GetLibNickname();
1575 
1576  if( nickname.IsEmpty() && GetCurPart() )
1577  id = GetCurPart()->GetLibId();
1578 
1579  return id;
1580 }
1581 
1582 
1584 {
1585  return getTargetLibId().GetLibNickname();
1586 }
1587 
1588 
1589 void LIB_EDIT_FRAME::SyncLibraries( bool aShowProgress )
1590 {
1591  LIB_ID selected;
1592 
1593  if( m_treePane )
1594  selected = m_treePane->GetLibTree()->GetSelectedLibId();
1595 
1596  if( aShowProgress )
1597  {
1598  wxProgressDialog progressDlg( _( "Loading Symbol Libraries" ), wxEmptyString,
1599  m_libMgr->GetAdapter()->GetLibrariesCount(), this );
1600 
1601  m_libMgr->Sync( true, [&]( int progress, int max, const wxString& libName )
1602  {
1603  progressDlg.Update( progress, wxString::Format( _( "Loading library \"%s\"" ), libName ) );
1604  } );
1605  }
1606  else
1607  {
1608  m_libMgr->Sync( true );
1609  }
1610 
1611  if( m_treePane )
1612  {
1613  wxDataViewItem found;
1614 
1615  if( selected.IsValid() )
1616  {
1617  // Check if the previously selected item is still valid,
1618  // if not - it has to be unselected to prevent crash
1619  found = m_libMgr->GetAdapter()->FindItem( selected );
1620 
1621  if( !found )
1623  }
1624 
1626 
1627  // Try to select the parent library, in case the part is not found
1628  if( !found && selected.IsValid() )
1629  {
1630  selected.SetLibItemName( "" );
1631  found = m_libMgr->GetAdapter()->FindItem( selected );
1632 
1633  if( found )
1634  m_treePane->GetLibTree()->SelectLibId( selected );
1635  }
1636  }
1637 }
1638 
1639 
1641 {
1642  wxArrayString libTableNames;
1643  libTableNames.Add( _( "Global" ) );
1644  libTableNames.Add( _( "Project" ) );
1645 
1646  wxSingleChoiceDialog dlg( this, _( "Choose the Library Table to add the library to:" ),
1647  _( "Add To Library Table" ), libTableNames );
1648 
1649  if( aOptional )
1650  {
1651  dlg.FindWindow( wxID_CANCEL )->SetLabel( _( "Skip" ) );
1652  dlg.FindWindow( wxID_OK )->SetLabel( _( "Add" ) );
1653  }
1654 
1655  if( dlg.ShowModal() != wxID_OK )
1656  return nullptr;
1657 
1658  switch( dlg.GetSelection() )
1659  {
1660  case 0: return &SYMBOL_LIB_TABLE::GetGlobalLibTable();
1661  case 1: return Prj().SchSymbolLibTable();
1662  default: return nullptr;
1663  }
1664 }
1665 
1666 
1667 bool LIB_EDIT_FRAME::backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt )
1668 {
1669  if( aOriginalFile.FileExists() )
1670  {
1671  wxFileName backupFileName( aOriginalFile );
1672  backupFileName.SetExt( "bck" );
1673 
1674  if( backupFileName.FileExists() )
1675  wxRemoveFile( backupFileName.GetFullPath() );
1676 
1677  if( !wxCopyFile( aOriginalFile.GetFullPath(), backupFileName.GetFullPath() ) )
1678  {
1679  DisplayError( this, _( "Failed to save backup document to file " ) +
1680  backupFileName.GetFullPath() );
1681  return false;
1682  }
1683  }
1684 
1685  return true;
1686 }
1687 
1688 
1690 {
1691  if( m_my_part && !GetCurLib().IsEmpty() && GetScreen()->IsModify() )
1692  m_libMgr->UpdatePart( m_my_part, GetCurLib() ); // UpdatePart() makes a copy
1693 }
1694 
1695 
1696 bool LIB_EDIT_FRAME::isCurrentPart( const LIB_ID& aLibId ) const
1697 {
1698  // This will return the root part of any alias
1699  LIB_PART* part = m_libMgr->GetBufferedPart( aLibId.GetLibItemName(), aLibId.GetLibNickname() );
1700  // Now we can compare the libId of the current part and the root part
1701  return ( part && GetCurPart() && part->GetLibId() == GetCurPart()->GetLibId() );
1702 }
1703 
1704 
1706 {
1707  SetCurLib( wxEmptyString );
1708  SetCurPart( nullptr );
1709  m_lastDrawItem = nullptr;
1710  SetDrawItem( NULL );
1713  Zoom_Automatique( false );
1714  Refresh();
1715 }
1716 
1717 
1719 {
1721 
1722  ReCreateHToolbar();
1723  ReCreateVToolbar();
1725  Layout();
1726  SendSizeEvent();
1727 }
1728 
1729 
1731 {
1732  // call my base class
1734 
1735  // tooltips in toolbars
1736  ReCreateHToolbar();
1737  ReCreateVToolbar();
1739 
1740  // status bar
1741  UpdateMsgPanel();
1742 }
1743 
1744 
1746 {
1747  EDA_DRAW_FRAME::SetScreen( aScreen );
1748 }
1749 
1750 
1752 {
1756 
1759 
1760  GetCanvas()->Refresh();
1761 }
1762 
1763 
1765 {
1766  RebuildView();
1767 }
1768 
1769 
1771 {
1772  LIB_PART* part = GetCurPart();
1773 
1774  if( !part )
1775  {
1776  return BOX2I( VECTOR2I(-100, -100), VECTOR2I( 200, 200 ) );
1777  }
1778  else
1779  {
1781  return BOX2I( boundingBox.GetOrigin(), VECTOR2I( boundingBox.GetWidth(), boundingBox.GetHeight() ) );
1782  }
1783 }
1784 
1785 
1787 {
1788  const std::string& payload = mail.GetPayload();
1789 
1790  switch( mail.Command() )
1791  {
1792  case MAIL_LIB_EDIT:
1793  if( !payload.empty() )
1794  {
1795  wxString libFileName( payload );
1796  wxString libNickname;
1797  wxString msg;
1798 
1799  SYMBOL_LIB_TABLE* libTable = Prj().SchSymbolLibTable();
1800  const LIB_TABLE_ROW* libTableRow = libTable->FindRowByURI( libFileName );
1801 
1802  if( !libTableRow )
1803  {
1804  msg.Printf( _( "The current configuration does not include the symbol library\n"
1805  "\"%s\".\nUse Manage Symbol Libraries to edit the configuration." ),
1806  libFileName );
1807  DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
1808  break;
1809  }
1810 
1811  libNickname = libTableRow->GetNickName();
1812 
1813  if( !libTable->HasLibrary( libNickname, true ) )
1814  {
1815  msg.Printf( _( "The library with the nickname \"%s\" is not enabled\n"
1816  "in the current configuration. Use Manage Symbol Libraries to\n"
1817  "edit the configuration." ), libNickname );
1818  DisplayErrorMessage( this, _( "Symbol library not enabled." ), msg );
1819  break;
1820  }
1821 
1822  SetCurLib( libNickname );
1823 
1824  if( m_treePane )
1825  {
1826  LIB_ID id( libNickname, wxEmptyString );
1827  m_treePane->GetLibTree()->ExpandLibId( id );
1828  m_treePane->GetLibTree()->CenterLibId( id );
1829  }
1830  }
1831 
1832  break;
1833 
1834  default:
1835  ;
1836  }
1837 }
void OnViewEntryDoc(wxCommandEvent &event)
#define TEXT_ANGLE_HORIZ
virtual wxPoint GetPosition() const =0
Return the current draw object position.
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:74
bool IsValid() const
Definition: lib_id.h:171
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
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:47
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
void OnToggleSearchTree(wxCommandEvent &event)
void OnUpdateEditingPart(wxUpdateUIEvent &event)
bool UnitsLocked() const
Check whether part units are interchangeable.
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:62
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:258
void CommonSettingsChanged() override
Function CommonSettingsChanged Notification event that some of the common (suite-wide) settings have ...
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
void SaveOneSymbol()
Saves the current symbol to a symbol file.
Definition: symbedit.cpp:153
Class KIWAY_EXPRESS carries a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:39
const EDA_RECT GetUnitBoundingBox(int aUnit, int aConvert) const
Get the bounding box for the symbol.
static double m_current_text_angle
Current text angle setting.
SCH_EDIT_FRAME::OnSelectTool SCH_EDIT_FRAME::OnEditItem ID_POPUP_GENERAL_END_RANGE
Part library alias object definition.
virtual void Zoom_Automatique(bool aWarpPointer) override
Redraw the screen with best zoom level and the best centering that shows all the page or the board...
bool IsMulti() const
void ReCreateOptToolbar()
Definition: tool_lib.cpp:201
#define LIB_EDIT_FRAME_NAME
Definition: draw_frame.h:49
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
virtual bool HandleBlockBegin(wxDC *aDC, EDA_KEY aKey, const wxPoint &aPosition, int aExplicitCommand=0) override
Initialize a block command.
LIB_EDIT_FRAME::Process_Special_Functions LIB_EDIT_FRAME::OnOrient EVT_UPDATE_UI_RANGE(ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_DELETE_ITEM_BUTT, LIB_EDIT_FRAME::OnUpdateEditingPart) LIB_EDIT_FRAME
FOOTPRINT_EDIT_FRAME::OnVerticalToolbar FOOTPRINT_EDIT_FRAME::ProcessPreferences FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions EVT_UPDATE_UI(ID_MODEDIT_LOAD_MODULE_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard) EVT_UPDATE_UI(ID_MODEDIT_INSERT_MODULE_IN_BOARD
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition: sch_view.cpp:179
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE...
PNG memory record (file in memory).
Definition: bitmap_types.h:43
#define MAX_SELECT_ITEM_IDS
The maximum number of items in the clarify selection context menu.
Definition: eeschema_id.h:42
virtual void OnEditSymbolLibTable(wxCommandEvent &aEvent)
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
static int m_convert
bool AppendUndo() const
void HardRedraw() override
Rebuild the GAL and redraw the screen.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:259
void RestoreComponent()
Restore the current edited component from its temporary copy.
LIB_ALIAS * GetAlias(size_t aIndex)
This file is part of the common library.
Define a symbol library graphical text item.
Definition: lib_text.h:44
void ClearTempCopyComponent()
Delete temporary copy of the current component and clear pointer.
void OnEditSymbolLibTable(wxCommandEvent &aEvent) override
virtual void SetScreen(BASE_SCREEN *aScreen)
Definition: draw_frame.h:178
double bestZoom(double sizeX, double sizeY, double scaleFactor, wxPoint centre)
Class CONTEXT_MENU.
Definition: context_menu.h:44
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:223
bool m_syncPinEdit
Set to true to not synchronize pins at the same position when editing symbols with multiple units or ...
double BestZoom() override
Return the zoom level which displays the full page on screen.
This file is part of the common library.
void OnConfigurePaths(wxCommandEvent &aEvent)
LIB_ALIASES GetAliases() const
void CommonSettingsChanged() override
Called after the preferences dialog is run.
LIB_EDIT_FRAME::Process_Special_Functions EVT_MENU_RANGE(ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE, LIB_EDIT_FRAME::Process_Special_Functions) EVT_MENU_RANGE(ID_LIBEDIT_MIRROR_X
void OnUpdateSyncPinEdit(wxUpdateUIEvent &event)
void SetScrollCenterPosition(const wxPoint &aPoint)
void ClearSearchTreeSelection()
void KiwayMailIn(KIWAY_EXPRESS &mail) override
Function KiwayMailIn receives KIWAY_EXPRESS messages from other players.
bool isCurrentPart(const LIB_ID &aLibId) const
Returns true if aLibId is an alias for the editor screen part.
Field object used in symbol libraries.
Definition: lib_field.h:59
virtual void OnActivate(wxActivateEvent &event) override
Called when the frame is activated.
void SetMessageBlock(EDA_DRAW_FRAME *frame)
Function SetMessageBlock Displays the type of block command in the status bar of the window...
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:91
LIB_MANAGER * m_libMgr
manager taking care of temporary modificatoins
void OnUpdateUndo(wxUpdateUIEvent &event)
void OnRotate(wxCommandEvent &aEvent)
Rotates the current item.
void UpdateAllItems(int aUpdateFlags)
Updates all items in the view according to the given flags.
Definition: view.cpp:1442
struct EDA_HOTKEY_CONFIG g_Libedit_Hokeys_Descr[]
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT
int GetHeight() const
Definition: eda_rect.h:118
void GlobalSetPins(LIB_PIN *aMasterPin, int aId)
Definition: pinedit.cpp:448
wxString SchematicLibraryFileWildcard()
virtual void EndMouseCapture(int aId=-1, int aCursorId=-1, const wxString &aTitle=wxEmptyString, bool aCallEndFunc=true)
Function EndMouseCapture ends mouse a capture.
bool InEditMode() const
Return the draw item editing mode status.
void OnUpdateRedo(wxUpdateUIEvent &event)
const LIB_ID & GetLibId() const
LIB_ID getTargetLibId() const
Returns either the part selected in the component tree, if context menu is active or the currently mo...
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, const wxPathList *aPaths)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:87
void SetSize(const Vec &size)
Definition: box2.h:210
void OnModify()
Must be called after a schematic change in order to set the "modify" flag of the current screen...
void OnSelectBodyStyle(wxCommandEvent &event)
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
void OnUpdateDeMorganNormal(wxUpdateUIEvent &event)
void LoadOneSymbol()
Read a component symbol file (*.sym ) and add graphic items to the current component.
Definition: symbedit.cpp:47
virtual void MirrorHorizontal(const wxPoint &aCenter)=0
Mirror the draw object along the horizontal (X) axis about aCenter point.
Class SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
#define DEFAULT_REPEAT_OFFSET_PIN
the default value (overwritten by the eeschema config)
Definition: general.h:50
wxAuiManager m_auimgr
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...
EDA_ITEM * GetItem(unsigned aIndex)
virtual void SetAutoPanRequest(bool aEnable)=0
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
size_t GetAliasCount() const
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
virtual void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
void OnUpdateSave(wxUpdateUIEvent &aEvent)
void OnUpdatePaste(wxUpdateUIEvent &event)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
void StartMoveDrawSymbol(wxDC *DC, LIB_ITEM *aItem)
Definition: symbdraw.cpp:269
void OnUpdateDeMorganConvert(wxUpdateUIEvent &event)
void OnUpdateRevert(wxUpdateUIEvent &aEvent)
int GetSelected() const
Function GetSelected() Returns the position of selected item.
Definition: context_menu.h:124
virtual void CallEndMouseCapture(wxDC *aDC)
Function CallEndMouseCapture calls the end mouse capture callback.
LIB_PART * m_my_part
a part I own, it is not in any library, but a copy could be.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
virtual bool HandleBlockEnd(wxDC *DC) override
Performs a block end command.
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
Pcbnew hotkeys.
Library Editor pane with component tree and symbol library table selector.
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:386
bool IsMenuActive() const
Returns the status of right-click context menu.
Definition: lib_tree.h:106
void OnOrient(wxCommandEvent &aEvent)
Handles the ID_LIBEDIT_MIRROR_X and ID_LIBEDIT_MIRROR_Y events.
void StartModifyDrawSymbol(wxDC *DC, LIB_ITEM *aItem)
Definition: symbdraw.cpp:292
void OnEditComponentProperties(wxCommandEvent &event)
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:59
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
void HideWorksheet()
Definition: sch_view.cpp:186
virtual void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase) override
Function CallMouseCapture calls the mouse capture callback.
Item is being added to the view.
Definition: view_item.h:60
bool AddLibrary(const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
Adds an existing library.
Definition: lib_manager.h:99
a helper to handle the real device context used in KiCad
LIB_PART * GetCurPart() const
Return the current part being edited or NULL if none selected.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
virtual const BOX2I GetDocumentExtents() const override
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SetDrawItem(LIB_ITEM *drawItem)
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
LIB_COLLECTOR m_collectedItems
Used for hit testing.
const std::string SchematicLibraryFileExtension
virtual void CrossHairOn(wxDC *DC=nullptr)
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
int ShowQuasiModal()
const LIB_TABLE_ROW * FindRowByURI(const wxString &aURI)
void OnUpdatePinTable(wxUpdateUIEvent &event)
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
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:144
SCH_DRAW_PANEL * GetCanvas() const override
wxComboBox * m_partSelectBox
a Box to select a part to edit (if any)
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
virtual void Rotate(const wxPoint &aCenter, bool aRotateCCW=true)=0
Rotate the object about aCenter point.
virtual void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
LIB_ITEM * locateItem(const wxPoint &aPosition, const KICAD_T aFilterList[])
void TempCopyComponent()
Create a temporary copy of the current edited component.
bool addLibraryFile(bool aCreateNew)
Creates or adds an existing library to the symbol library table.
Define a library symbol object.
Definition of file extensions used in Kicad.
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:174
unsigned STATUS_FLAGS
Definition: base_struct.h:147
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
bool saveSymbolLibTables(bool aGlobal, bool aProject)
Saves Symbol Library Tables to disk.
bool IsLibraryModified(const wxString &aLibrary) const
Returns true if library has unsaved modifications.
virtual void CrossHairOff(wxDC *DC=nullptr)
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
static int m_textPinNumDefaultSize
The default pin num text size setting.
#define KICAD_DEFAULT_DRAWFRAME_STYLE
static LIB_ITEM * m_lastDrawItem
void SetCurrentLib(const wxString &aLibrary)
Sets the currently modified library name.
Definition: lib_manager.h:248
virtual void MirrorVertical(const wxPoint &aCenter)=0
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
EVT_TOOL(ID_FOOTPRINT_WIZARD_SELECT_WIZARD, FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard) EVT_TOOL(ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT
static int m_textSize
The current text size setting.
wxPoint Centre() const
Definition: eda_rect.h:60
void SetCurrentPart(const wxString &aPart)
Sets the currently modified part name.
Definition: lib_manager.h:264
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg)
Set the tool command ID to aId and sets the cursor to aCursor.
void Collect(LIB_ITEMS_CONTAINER &aItem, const KICAD_T aFilterList[], const wxPoint &aPosition, int aUnit=0, int aConvert=0)
Function Collect scans a SCH_ITEM using this class&#39;s Inspector method, which does the collection...
void OnSelectTool(wxCommandEvent &aEvent)
bool m_showPinElectricalTypeName
the option to show the pin electrical name in the component editor
void OnShowElectricalType(wxCommandEvent &event)
From Option toolbar: option to show the electrical pin type name.
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1538
KIGFX::SCH_VIEW * GetView() const
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory)
The the schematic editor to refresh the display.
Definition: mail_type.h:49
LIB_PART(const wxString &aName, PART_LIB *aLibrary=NULL)
Specialization of the wxAuiPaneInfo class for KiCad panels.
wxAuiToolBar * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:157
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
void Process_Special_Functions(wxCommandEvent &event)
Definition: solve.cpp:178
void SetAbortRequest(bool aAbortRequest)
bool IsLibraryReadOnly(const wxString &aLibrary) const
Returns true if the library is stored in a read-only file.
LIB_EDIT_FRAME::Process_Special_Functions ID_LIBEDIT_ORIENT_NORMAL
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
void emptyScreen()
Restores the empty editor screen, without any part or library selected.
bool UpdatePart(LIB_PART *aPart, const wxString &aLibrary)
Updates the part buffer with a new version of the part.
void DisplayCmpDoc()
Display the documentation of the selected component.
Definition: libedit.cpp:777
void updateTitle()
Updates the main window title bar with the current library name and read only status of the library...
Definition: libedit.cpp:58
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
FOOTPRINT_EDIT_FRAME::OnVerticalToolbar EVT_MENU(ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, FOOTPRINT_EDIT_FRAME::ProcessPreferences) EVT_MENU(ID_PCB_LIB_TABLE_EDIT
LIB_PART * GetPart() const
Get the shared LIB_PART.
void OnUpdateSaveAs(wxUpdateUIEvent &aEvent)
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:463
int GetUnitCount() const
const 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
LIB_PIN * GetNextPin(LIB_PIN *aItem=NULL)
Return the next pin object from the draw list.
static int m_textPinNameDefaultSize
The default pin name text size setting.
Class to handle modifications to the symbol libraries.
Definition: lib_manager.h:49
void EditSymbolText(wxDC *DC, LIB_ITEM *DrawItem)
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition: lib_tree.cpp:179
void deleteItem(wxDC *aDC, LIB_ITEM *aItem)
Deletes the currently selected draw item.
const wxString & GetDocFileName() const
void storeCurrentPart()
Stores the currently modified part in the library manager buffer.
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
bool backupFile(const wxFileName &aOriginalFile, const wxString &aBackupExt)
Creates a backup copy of a file with requested extension
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:123
void OnSelectItem(wxCommandEvent &aEvent)
void SyncLibraries(bool aShowProgress)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
void OnOpenPinTable(wxCommandEvent &aEvent)
wxString getTargetLib() const
Returns either the library selected in the component tree, if context menu is active or the library t...
#define GR_DEFAULT_DRAWMODE
Definition: general.h:70
void OnUpdateSelectTool(wxUpdateUIEvent &aEvent)
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_ITEM * LocateItemUsingCursor(const wxPoint &aPosition, const KICAD_T aFilterList[]=LIB_COLLECTOR::AllItems)
LIB_PART * GetBufferedPart(const wxString &aAlias, const wxString &aLibrary)
Returns the part copy from the buffer.
const wxString & GetNickName() const
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Return the nearest aGridSize location to aPosition.
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:92
BLOCK_SELECTOR m_clipboard
Clipboard buffer storing LIB_ITEMs
see class PGM_BASE
TRANSFORM DefaultTransform
Definition: eeschema.cpp:59
void ReCreateHToolbar() override
Definition: tool_lib.cpp:103
bool GetShowDeMorgan()
void ShowChangedLanguage() override
Function ShowChangedLanguage redraws the menus and what not in current language.
virtual void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform)
Draw an item.
static int m_unit
LIB_ITEM * GetCurLibItem() const
Definition: sch_screen.h:197
bool saveAllLibraries(bool aRequireConfirmation)
Definition: libedit.cpp:733
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
BLOCK_STATE_T GetState() const
EVT_TOOL_RANGE(ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_DELETE_ITEM_BUTT, LIB_EDIT_FRAME::OnSelectTool) EVT_MENU_RANGE(ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_ITEM
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
virtual void HandleBlockPlace(wxDC *DC) override
Handles the block place command.
int GetToolId() const
Definition: draw_frame.h:516
static FILL_T m_drawFillStyle
The current draw or edit graphic item fill style.
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy, UNDO_REDO_T undoType=UR_LIBEDIT)
Create a copy of the current component, and save it in the undo list.
void SetCurItem(SCH_ITEM *aItem)
Sets the currently selected object, m_CurrentItem.
Definition: sch_screen.h:204
virtual void SetScreen(BASE_SCREEN *aScreen) override
void EndDrawGraphicItem(wxDC *DC)
Definition: symbdraw.cpp:306
size_t i
Definition: json11.cpp:597
LIB_ITEM * GetDrawItem() const
LIB_TREE * GetLibTree() const
void SetIgnoreMouseEvents(bool aIgnore)
void SetOrigin(const Vec &pos)
Definition: box2.h:208
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
static wxString SubReference(int aUnit, bool aAddSeparator=true)
void RemoveDrawItem(LIB_ITEM *aItem, EDA_DRAW_PANEL *aPanel=NULL, wxDC *aDc=NULL)
Remove draw aItem from list.
static int m_defaultPinLength
Default pin length.
void EditGraphicSymbol(wxDC *DC, LIB_ITEM *DrawItem)
Definition: symbdraw.cpp:54
LIB_ALIAS * 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...
int GetWidth() const
Definition: eda_rect.h:117
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
#define DEFAULTPINNAMESIZE
Definition: general.h:68
wxString GetUniqueLibraryName() const
Returns a library name that is not currently in use.
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:54
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
const wxString & GetName() const
bool SynchronizePins()
Pin editing (add, delete, move...) can be synchronized between units when units are interchangeable b...
void OnUpdateElectricalType(wxUpdateUIEvent &aEvent)
bool IsEditingDrawItem()
Definition of class LIB_EDIT_FRAME.
BLOCK_COMMAND_T GetCommand() const
bool IsPartModified(const wxString &aAlias, const wxString &aLibrary) const
Returns true if part has unsaved modifications.
SCH_SCREEN * m_dummyScreen
Helper screen used when no part is loaded
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:925
void OnUpdateHavePart(wxUpdateUIEvent &aEvent)
void EditField(LIB_FIELD *Field)
Definition: libfield.cpp:42
wxString SetCurLib(const wxString &aLibNickname)
Sets the current library nickname and returns the old library nickname.
static int m_drawLineWidth
Default line width for drawing or editing graphic items.
SYMBOL_LIB_TABLE * selectSymLibTable(bool aOptional=false)
Displays a dialog asking the user to select a symbol library table.
Definition for part library class.
#define DEFAULTPINNUMSIZE
The default pin name size when creating pins(can be changed in preference menu)
Definition: general.h:65
static bool m_showDeMorgan
void SetModify()
Definition: base_screen.h:324
MAIL_T Command()
Function Command returns the MAIL_T associated with this mail.
Definition: kiway_express.h:52
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
SYMBOL_TREE_PANE * m_treePane
component search tree widget
BASE_SCREEN class implementation.
bool m_drawSpecificUnit
Specify which component parts the current draw item applies to.
Message panel definition file.
void OnSelectPart(wxCommandEvent &event)
EDA_UNITS_T m_UserUnits
Definition: draw_frame.h:120
LIB_TREE_MODEL_ADAPTER::PTR & GetAdapter()
Returns the adapter object that provides the stored data.
Definition: lib_manager.h:235
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME, and SCH_EDIT_FRAME, and it brings in a common way of handling the provided virtual functions for the derived classes.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
virtual void ShowChangedLanguage()
Function ShowChangedLanguage redraws the menus and what not in current language.
void UpdatePartSelectList()
unsigned GetCount() const
virtual void OnActivate(wxActivateEvent &event)
Called when activating the frame.
void DisplayComponent(const LIB_PART *aComponent)
Function DisplayBoard FIXME adds all items from the current board to the VIEW, so they can be display...
LIB_PART * getTargetPart() const
Returns currently edited part.
void ClearMsgPanel(void)
Clear all messages from the message panel.
static wxSize m_clientSize
void Regenerate()
Updates the component tree
void OnUpdateSearchTreeTool(wxUpdateUIEvent &aEvent)
bool GetShowElectricalType()
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:168
void SetCommand(BLOCK_COMMAND_T aCommand)
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:162
virtual void UpdateMsgPanel()
Redraw the message panel.
void StartMovePin(LIB_ITEM *aPin)
Prepare the displacement of a pin.
Definition: pinedit.cpp:278
int GetConvert() const
bool UpdatePartAfterRename(LIB_PART *aPart, const wxString &oldAlias, const wxString &aLibrary)
Updates the part buffer with a new version of the part when the name has changed. ...
LIB_PART * m_tempCopyComponent
temp copy of a part during edit, I own it here.
void ReCreateVToolbar() override
Definition: tool_lib.cpp:48