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 
209  m_my_part = NULL;
210  m_tempCopyComponent = NULL;
211  m_treePane = nullptr;
212  m_libMgr = nullptr;
213 
214  // Delayed initialization
215  if( m_textSize == -1 )
216  m_textSize = GetDefaultTextSize();
217 
218  // Initialize grid id to the default value 50 mils:
220 
221  wxIcon icon;
222  icon.CopyFromBitmap( KiBitmap( icon_libedit_xpm ) );
223  SetIcon( icon );
224 
225  LoadSettings( config() );
226 
227  m_dummyScreen = new SCH_SCREEN( aKiway );
228  SetScreen( m_dummyScreen );
229  GetScreen()->m_Center = true;
230  GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
231 
232  SetCrossHairPosition( wxPoint( 0, 0 ) );
233 
234  SetPresetGrid( m_LastGridSizeId );
235 
236  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
237 
238  if( m_canvas )
239  m_canvas->SetEnableBlockCommands( true );
240 
241  m_libMgr = new LIB_MANAGER( *this );
242  SyncLibraries( true );
243  m_treePane = new SYMBOL_TREE_PANE( this, m_libMgr );
244 
245  ReCreateMenuBar();
246  ReCreateHToolbar();
247  ReCreateVToolbar();
248  ReCreateOptToolbar();
249 
250  updateTitle();
251  DisplayCmpDoc();
252  UpdatePartSelectList();
253 
254  m_auimgr.SetManagedWindow( this );
255  m_auimgr.SetArtProvider( new EDA_DOCKART( this ) );
256 
257 
258  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
259  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
260 
261  m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) );
262  m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "ComponentTree" ).Left().Layer(1)
263  .Caption( _( "Libraries" ) ).MinSize( 250, -1 ).Resizable() );
264  m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ).Right().Layer(1) );
265 
266  m_auimgr.AddPane( m_canvas->GetWindow(), wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
267 
268  m_auimgr.Update();
269 
270  Raise();
271  Show( true );
272 
273  Bind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnConfigurePaths, this,
275 
276  Bind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnEditSymbolLibTable, this,
278 
279  wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, ID_ZOOM_PAGE );
280  wxPostEvent( this, evt );
281 
282  SyncView();
283  GetGalCanvas()->GetViewControls()->SetSnapping( true );
284  GetGalCanvas()->GetView()->UseDrawPriority( true );
285  GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
286  GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
287 }
288 
289 
291 {
292  Unbind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnEditSymbolLibTable, this,
294 
295  // current screen is destroyed in EDA_DRAW_FRAME
297 
298  m_lastDrawItem = NULL;
300 
301  delete m_tempCopyComponent;
302  delete m_libMgr;
303  delete m_my_part;
304 }
305 
306 
307 void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
308 {
309  if( saveAllLibraries( true ) )
310  Destroy();
311  else
312  Event.Veto();
313 }
314 
315 
317 {
318  LIB_PART* part = GetCurPart();
319  double defaultLibraryZoom = 7.33;
320 
321  if( !part )
322  {
323  SetScrollCenterPosition( wxPoint( 0, 0 ) );
324  return defaultLibraryZoom;
325  }
326 
328 
329  double sizeX = (double) boundingBox.GetWidth();
330  double sizeY = (double) boundingBox.GetHeight();
331  wxPoint centre = boundingBox.Centre();
332 
333  // Reserve a 20% margin around component bounding box.
334  double margin_scale_factor = 1.2;
335 
336  return bestZoom( sizeX, sizeY, margin_scale_factor, centre);
337 }
338 
339 
341 {
342  if( m_partSelectBox == NULL )
343  return;
344 
345  if( m_partSelectBox->GetCount() != 0 )
346  m_partSelectBox->Clear();
347 
348  LIB_PART* part = GetCurPart();
349 
350  if( !part || part->GetUnitCount() <= 1 )
351  {
352  m_unit = 1;
353  m_partSelectBox->Append( wxEmptyString );
354  }
355  else
356  {
357  for( int i = 0; i < part->GetUnitCount(); i++ )
358  {
359  wxString sub = LIB_PART::SubReference( i+1, false );
360  wxString unit = wxString::Format( _( "Unit %s" ), GetChars( sub ) );
361  m_partSelectBox->Append( unit );
362  }
363  }
364 
365  // Ensure the current selected unit is compatible with
366  // the number of units of the current part:
367  if( part && part->GetUnitCount() < m_unit )
368  m_unit = 1;
369 
370  m_partSelectBox->SetSelection( ( m_unit > 0 ) ? m_unit - 1 : 0 );
371 }
372 
373 
374 void LIB_EDIT_FRAME::OnShowElectricalType( wxCommandEvent& event )
375 {
377 
378  // Update canvas
381  GetCanvas()->Refresh();
382 }
383 
384 
385 void LIB_EDIT_FRAME::OnToggleSearchTree( wxCommandEvent& event )
386 {
387  auto& treePane = m_auimgr.GetPane( m_treePane );
388  treePane.Show( !IsSearchTreeShown() );
389  m_auimgr.Update();
390 }
391 
392 
393 void LIB_EDIT_FRAME::OnEditSymbolLibTable( wxCommandEvent& aEvent )
394 {
395  m_libMgr->GetAdapter()->Freeze();
396 
398  SyncLibraries( true );
399 
400  m_libMgr->GetAdapter()->Thaw();
401 }
402 
403 
405 {
406  return m_auimgr.GetPane( m_treePane ).IsShown();
407 }
408 
409 
411 {
413 }
414 
415 
416 void LIB_EDIT_FRAME::OnUpdateSelectTool( wxUpdateUIEvent& aEvent )
417 {
418  if( aEvent.GetEventObject() == m_drawToolBar || aEvent.GetEventObject() == m_mainToolBar )
419  aEvent.Check( GetToolId() == aEvent.GetId() );
420 }
421 
422 
423 void LIB_EDIT_FRAME::OnUpdateElectricalType( wxUpdateUIEvent& aEvent )
424 {
425  aEvent.Check( GetShowElectricalType() );
426 }
427 
428 
429 void LIB_EDIT_FRAME::OnUpdateSearchTreeTool( wxUpdateUIEvent& aEvent )
430 {
431  aEvent.Check( IsSearchTreeShown() );
432 }
433 
434 
435 void LIB_EDIT_FRAME::OnUpdateSave( wxUpdateUIEvent& aEvent )
436 {
437  LIB_ID libId = getTargetLibId();
438  const wxString& libName = libId.GetLibNickname();
439  const wxString& partName = libId.GetLibItemName();
440  bool readOnly = libName.IsEmpty() || m_libMgr->IsLibraryReadOnly( libName );
441 
442  if( partName.IsEmpty() )
443  aEvent.Enable( !readOnly && m_libMgr->IsLibraryModified( libName ) );
444  else
445  aEvent.Enable( !readOnly && m_libMgr->IsPartModified( partName, libName ) );
446 }
447 
448 
449 void LIB_EDIT_FRAME::OnUpdateSaveAs( wxUpdateUIEvent& aEvent )
450 {
451  LIB_ID libId = getTargetLibId();
452  const wxString& libName = libId.GetLibNickname();
453  const wxString& partName = libId.GetLibItemName();
454 
455  aEvent.Enable( !libName.IsEmpty() || !partName.IsEmpty() );
456 }
457 
458 
459 void LIB_EDIT_FRAME::OnUpdateRevert( wxUpdateUIEvent& aEvent )
460 {
461  LIB_ID libId = getTargetLibId();
462  const wxString& libName = libId.GetLibNickname();
463  const wxString& partName = libId.GetLibItemName();
464 
465  if( partName.IsEmpty() )
466  aEvent.Enable( !libName.IsEmpty() && m_libMgr->IsLibraryModified( libName ) );
467  else
468  aEvent.Enable( !libName.IsEmpty() && m_libMgr->IsPartModified( partName, libName ) );
469 }
470 
471 
472 void LIB_EDIT_FRAME::OnUpdateHavePart( wxUpdateUIEvent& aEvent )
473 {
474  aEvent.Enable( getTargetLibId().IsValid() );
475 }
476 
477 
478 void LIB_EDIT_FRAME::OnUpdateEditingPart( wxUpdateUIEvent& aEvent )
479 {
480  LIB_PART* part = GetCurPart();
481 
482  aEvent.Enable( part != NULL );
483 
484  if( part && aEvent.GetEventObject() == m_drawToolBar )
485  aEvent.Check( GetToolId() == aEvent.GetId() );
486 }
487 
488 
489 void LIB_EDIT_FRAME::OnUpdatePaste( wxUpdateUIEvent& event )
490 {
491  event.Enable( m_clipboard.GetCount() > 0 );
492 }
493 
494 
495 void LIB_EDIT_FRAME::OnUpdateUndo( wxUpdateUIEvent& event )
496 {
497  event.Enable( GetCurPart() && GetScreen() &&
498  GetScreen()->GetUndoCommandCount() != 0 && !IsEditingDrawItem() );
499 }
500 
501 
502 void LIB_EDIT_FRAME::OnUpdateRedo( wxUpdateUIEvent& event )
503 {
504  event.Enable( GetCurPart() && GetScreen() &&
505  GetScreen()->GetRedoCommandCount() != 0 && !IsEditingDrawItem() );
506 }
507 
508 
509 void LIB_EDIT_FRAME::OnUpdateSyncPinEdit( wxUpdateUIEvent& event )
510 {
511  LIB_PART* part = GetCurPart();
512  event.Enable( part && part->IsMulti() && !part->UnitsLocked() );
513  event.Check( m_syncPinEdit );
514 }
515 
516 
517 void LIB_EDIT_FRAME::OnUpdatePinTable( wxUpdateUIEvent& event )
518 {
519  LIB_PART* part = GetCurPart();
520  event.Enable( part != NULL );
521 }
522 
523 
524 void LIB_EDIT_FRAME::OnUpdatePartNumber( wxUpdateUIEvent& event )
525 {
526  if( m_partSelectBox == NULL )
527  return;
528 
529  LIB_PART* part = GetCurPart();
530 
531  // Using the typical event.Enable() call doesn't seem to work with wxGTK
532  // so use the pointer to alias combobox to directly enable or disable.
533  m_partSelectBox->Enable( part && part->GetUnitCount() > 1 );
534 }
535 
536 
537 void LIB_EDIT_FRAME::OnUpdateDeMorganNormal( wxUpdateUIEvent& event )
538 {
539  if( m_mainToolBar == NULL )
540  return;
541 
542  LIB_PART* part = GetCurPart();
543 
544  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
545  event.Check( m_convert <= 1 );
546 }
547 
548 
549 void LIB_EDIT_FRAME::OnUpdateDeMorganConvert( wxUpdateUIEvent& event )
550 {
551  if( m_mainToolBar == NULL )
552  return;
553 
554  LIB_PART* part = GetCurPart();
555 
556  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
557  event.Check( m_convert > 1 );
558 }
559 
560 
561 void LIB_EDIT_FRAME::OnSelectPart( wxCommandEvent& event )
562 {
563  int i = event.GetSelection();
564 
565  if( ( i == wxNOT_FOUND ) || ( ( i + 1 ) == m_unit ) )
566  return;
567 
568  m_lastDrawItem = NULL;
569  m_unit = i + 1;
570 
571  RebuildView();
572  DisplayCmpDoc();
573 }
574 
575 
576 void LIB_EDIT_FRAME::OnViewEntryDoc( wxCommandEvent& event )
577 {
578  LIB_PART* part = GetCurPart();
579 
580  if( !part )
581  return;
582 
583  wxString filename;
584 
585  if( part->GetAliasCount() > 1 )
586  {
587  CONTEXT_MENU popup;
588  wxString msg;
589  int id = 0;
590 
591  for( LIB_ALIAS* alias : part->GetAliases() )
592  {
593  msg.Printf( wxT( "%s (%s)" ), alias->GetName(), alias->GetDocFileName() );
594  popup.Append( id++, msg );
595  }
596 
597  PopupMenu( &popup );
598 
599  if( popup.GetSelected() >= 0 )
600  filename = part->GetAlias( (unsigned) popup.GetSelected() )->GetDocFileName();
601  }
602  else
603  filename = part->GetAlias( 0 )->GetDocFileName();
604 
605  if( !filename.IsEmpty() && filename != wxT( "~" ) )
606  {
607  SEARCH_STACK* lib_search = Prj().SchSearchS();
608 
609  GetAssociatedDocument( this, filename, lib_search );
610  }
611 }
612 
613 
614 void LIB_EDIT_FRAME::OnSelectBodyStyle( wxCommandEvent& event )
615 {
616  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
617 
618  if( event.GetId() == ID_DE_MORGAN_NORMAL_BUTT )
619  m_convert = 1;
620  else
621  m_convert = 2;
622 
623  m_lastDrawItem = NULL;
624 
625  RebuildView();
626 }
627 
628 
629 void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
630 {
631  int id = event.GetId();
632  wxPoint pos;
633  SCH_SCREEN* screen = GetScreen();
635  LIB_ITEM* item = screen->GetCurLibItem();
636 
638 
639  wxGetMousePosition( &pos.x, &pos.y );
640  pos.y += 20;
641 
642  switch( id ) // Stop placement commands before handling new command.
643  {
644  case wxID_COPY:
645  case ID_POPUP_COPY_BLOCK:
646  case wxID_CUT:
647  case ID_POPUP_CUT_BLOCK:
649  case ID_LIBEDIT_EDIT_PIN:
655  case ID_POPUP_ZOOM_BLOCK:
664  break;
665 
667  if( m_canvas->IsMouseCaptured() )
669  else
670  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
671  break;
672 
675  break;
676 
677  default:
678  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor(),
679  wxEmptyString );
680  break;
681  }
682 
683  switch( id )
684  {
686  break;
687 
690  break;
691 
694  if( item )
695  {
696  EndDrawGraphicItem( nullptr );
697  }
698  break;
699 
701  if( item )
702  {
704 
705  switch( item->Type() )
706  {
707  case LIB_ARC_T:
708  case LIB_CIRCLE_T:
709  case LIB_RECTANGLE_T:
710  case LIB_POLYLINE_T:
711  EditGraphicSymbol( nullptr, item );
712  break;
713 
714  case LIB_TEXT_T:
715  EditSymbolText( nullptr, item );
716  break;
717 
718  default:
719  ;
720  }
721 
722  m_canvas->CrossHairOn( );
723  }
724  break;
725 
727  {
728  // Delete the last created segment, while creating a polyline draw item
729  if( item == NULL )
730  break;
731 
733  STATUS_FLAGS oldFlags = item->GetFlags();
734  item->ClearFlags();
735  /* item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
736  DefaultTransform );
737  ( (LIB_POLYLINE*) item )->DeleteSegment( GetCrossHairPosition( true ) );
738  item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
739  DefaultTransform );*/
740  item->SetFlags( oldFlags );
741  m_lastDrawItem = NULL;
742  }
743  break;
744 
746  if( item )
747  deleteItem( nullptr, item );
748 
749  break;
750 
752  if( item == NULL )
753  break;
754 
755  if( item->Type() == LIB_PIN_T )
756  {
757  StartMovePin( item );
758  }
759  else
760  {
761  StartMoveDrawSymbol( nullptr, item );
762  }
763  break;
764 
766 
767  if( item == NULL )
768  break;
769 
771  if( item->Type() == LIB_RECTANGLE_T
772  || item->Type() == LIB_CIRCLE_T
773  || item->Type() == LIB_POLYLINE_T
774  || item->Type() == LIB_ARC_T
775  )
776  {
777  StartModifyDrawSymbol( nullptr, item );
778  }
779 
780  break;
781 
783  if( item == NULL )
784  break;
785 
786  m_canvas->CrossHairOff( nullptr );
787 
788  if( item->Type() == LIB_FIELD_T )
789  {
790  EditField( (LIB_FIELD*) item );
791  }
792 
794  m_canvas->CrossHairOn( );
795  break;
796 
800  {
801  if( !item || item->Type() != LIB_PIN_T )
802  break;
803 
804  LIB_PART* part = GetCurPart();
805 
806  SaveCopyInUndoList( part );
807 
808  GlobalSetPins( (LIB_PIN*) item, id );
810  }
811  break;
812 
813  case ID_POPUP_ZOOM_BLOCK:
814  m_canvas->SetAutoPanRequest( false );
815  block.SetCommand( BLOCK_ZOOM );
816  HandleBlockEnd( nullptr );
817  break;
818 
820  m_canvas->SetAutoPanRequest( false );
821  block.SetCommand( BLOCK_DELETE );
823  HandleBlockEnd( nullptr );
824  break;
825 
827  m_canvas->SetAutoPanRequest( false );
828  block.SetCommand( BLOCK_DUPLICATE );
830  HandleBlockEnd( nullptr );
831  break;
832 
834  m_canvas->SetAutoPanRequest( false );
837  HandleBlockEnd( nullptr );
838  break;
839 
842  OnOrient( event );
843  break;
844 
846  OnRotate( event );
847  break;
848 
850  m_canvas->SetAutoPanRequest( false );
852  HandleBlockPlace( nullptr );
853  break;
854 
855  case wxID_COPY:
856  case ID_POPUP_COPY_BLOCK:
857  block.SetCommand( BLOCK_COPY );
858  block.SetMessageBlock( this );
859  HandleBlockEnd( nullptr );
860  break;
861 
862  case wxID_PASTE:
865  break;
866 
867  case wxID_CUT:
868  case ID_POPUP_CUT_BLOCK:
869  if( block.GetCommand() != BLOCK_MOVE )
870  break;
871 
872  block.SetCommand( BLOCK_CUT );
873  block.SetMessageBlock( this );
874  HandleBlockEnd( nullptr );
875  break;
876 
877  default:
878  wxFAIL_MSG( "LIB_EDIT_FRAME::Process_Special_Functions error" );
879  break;
880  }
881 
882  m_canvas->SetIgnoreMouseEvents( false );
883 
884  if( GetToolId() == ID_NO_TOOL_SELECTED )
885  m_lastDrawItem = NULL;
886 }
887 
888 
889 void LIB_EDIT_FRAME::OnActivate( wxActivateEvent& event )
890 {
892 }
893 
894 
896 {
897  wxString libNickname = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_LIB );
898 
899  if( !libNickname.empty() )
900  {
901  if( !Prj().SchSymbolLibTable()->HasLibrary( libNickname ) )
902  {
903  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
904  libNickname = wxEmptyString;
905  }
906  }
907 
908  return libNickname;
909 }
910 
911 
912 wxString LIB_EDIT_FRAME::SetCurLib( const wxString& aLibNickname )
913 {
914  wxString old = GetCurLib();
915 
916  if( aLibNickname.empty() || !Prj().SchSymbolLibTable()->HasLibrary( aLibNickname ) )
917  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
918  else
919  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, aLibNickname );
920 
921  m_libMgr->SetCurrentLib( aLibNickname );
922 
923  return old;
924 }
925 
926 
928 {
929  if( !aPart && !m_my_part )
930  return;
931 
932  wxASSERT( m_my_part != aPart );
933  GetScreen()->SetCurItem( nullptr );
934 
935  if( m_my_part != aPart )
936  {
937  if( m_my_part )
938  delete m_my_part;
939 
940  m_my_part = aPart;
941  }
942 
943  // select the current component in the tree widget
944  if( aPart )
945  m_treePane->GetLibTree()->SelectLibId( aPart->GetLibId() );
946 
947  wxString partName = aPart ? aPart->GetName() : wxString();
948  m_libMgr->SetCurrentPart( partName );
949 
950  // retain in case this wxFrame is re-opened later on the same PROJECT
952 
953  // Ensure synchronized pin edit can be enabled only symbols with interchangeable units
954  m_syncPinEdit = aPart && aPart->IsMulti() && !aPart->UnitsLocked();
955 
956  RebuildView();
957 }
958 
959 
961 {
962  delete m_tempCopyComponent;
963 
964  if( LIB_PART* part = GetCurPart() )
965  // clone it and own the clone.
966  m_tempCopyComponent = new LIB_PART( *part );
967  else
968  // clear it, there was no CurPart
969  m_tempCopyComponent = NULL;
970 }
971 
972 
974 {
975  if( m_tempCopyComponent )
976  {
977  // transfer ownership to CurPart
979  m_tempCopyComponent = NULL;
980  }
981 }
982 
983 
985 {
986  delete m_tempCopyComponent;
987  m_tempCopyComponent = NULL;
988 }
989 
990 
991 void LIB_EDIT_FRAME::EditSymbolText( wxDC* DC, LIB_ITEM* DrawItem )
992 {
993  if ( ( DrawItem == NULL ) || ( DrawItem->Type() != LIB_TEXT_T ) )
994  return;
995 
996  // Deleting old text
997  if( DC && !DrawItem->InEditMode() )
998  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
1000 
1001  DIALOG_LIB_EDIT_TEXT dlg( this, (LIB_TEXT*) DrawItem );
1002 
1003  if( dlg.ShowModal() != wxID_OK )
1004  return;
1005 
1006  GetCanvas()->GetView()->Update( DrawItem );
1007  GetCanvas()->Refresh();
1008  OnModify();
1009 
1010  // Display new text
1011  if( DC && !DrawItem->InEditMode() )
1012  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, GR_DEFAULT_DRAWMODE,
1013  NULL, DefaultTransform );
1014 }
1015 
1016 
1017 void LIB_EDIT_FRAME::OnEditComponentProperties( wxCommandEvent& event )
1018 {
1019  bool partLocked = GetCurPart()->UnitsLocked();
1020  wxString oldName = GetCurPart()->GetName();
1021 
1022  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
1023 
1024  if( GetDrawItem() && GetDrawItem()->Type() == LIB_FIELD_T )
1025  SetDrawItem( nullptr ); // selected LIB_FIELD might be deleted
1026 
1028 
1029  // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
1030  // frame. Therefore this dialog as a modal frame parent, MUST be run under
1031  // quasimodal mode for the quasimodal frame support to work. So don't use
1032  // the QUASIMODAL macros here.
1033  if( dlg.ShowQuasiModal() != wxID_OK )
1034  return;
1035 
1036  // if m_UnitSelectionLocked has changed, set some edit options or defaults
1037  // to the best value
1038  if( partLocked != GetCurPart()->UnitsLocked() )
1039  {
1040  // Enable synchronized pin edit mode for symbols with interchangeable units
1042  // also set default edit options to the better value
1043  // Usually if units are locked, graphic items are specific to each unit
1044  // and if units are interchangeable, graphic items are common to units
1046  }
1047 
1048  if( oldName != GetCurPart()->GetName() )
1050  else
1052 
1054  updateTitle();
1055  DisplayCmpDoc();
1056 
1057  RebuildView();
1058  GetCanvas()->Refresh();
1059  OnModify();
1060 }
1061 
1062 
1063 void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
1064 {
1065  int id = aEvent.GetId();
1066  int lastToolID = GetToolId();
1067 
1069  m_lastDrawItem = NULL;
1070 
1071  // Stop the current command and deselect the current tool.
1072  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
1073 
1074  LIB_PART* part = GetCurPart();
1075 
1076  switch( id )
1077  {
1078  case ID_NO_TOOL_SELECTED:
1079  SetToolID( id, GetGalCanvas()->GetDefaultCursor(), wxEmptyString );
1080  break;
1081 
1083  case ID_ZOOM_SELECTION:
1084  // This tool is located on the main toolbar: switch it on or off on click on it
1085  if( lastToolID != ID_ZOOM_SELECTION )
1086  SetToolID( ID_ZOOM_SELECTION, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) );
1087  else
1089  break;
1090 
1091  case ID_LIBEDIT_PIN_BUTT:
1092  if( part )
1093  {
1094  SetToolID( id, wxCURSOR_PENCIL, _( "Add pin" ) );
1095  }
1096  else
1097  {
1098  SetToolID( id, wxCURSOR_ARROW, _( "Set pin options" ) );
1099 
1100  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
1101 
1102  cmd.SetId( ID_LIBEDIT_EDIT_PIN );
1103  GetEventHandler()->ProcessEvent( cmd );
1105  }
1106  break;
1107 
1109  SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) );
1110  break;
1111 
1113  SetToolID( id, wxCURSOR_PENCIL, _( "Add rectangle" ) );
1114  break;
1115 
1117  SetToolID( id, wxCURSOR_PENCIL, _( "Add circle" ) );
1118  break;
1119 
1121  SetToolID( id, wxCURSOR_PENCIL, _( "Add arc" ) );
1122  break;
1123 
1125  SetToolID( id, wxCURSOR_PENCIL, _( "Add line" ) );
1126  break;
1127 
1129  SetToolID( id, wxCURSOR_HAND, _( "Set anchor position" ) );
1130  break;
1131 
1133  SetToolID( id, GetGalCanvas()->GetDefaultCursor(), _( "Import" ) );
1134  LoadOneSymbol();
1136  break;
1137 
1139  SetToolID( id, GetGalCanvas()->GetDefaultCursor(), _( "Export" ) );
1140  SaveOneSymbol();
1142  break;
1143 
1145  if( !part )
1146  {
1147  wxBell();
1148  break;
1149  }
1150 
1151  SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
1152  break;
1153 
1154  default:
1155  break;
1156  }
1157 
1158  m_canvas->SetIgnoreMouseEvents( false );
1159 }
1160 
1161 
1162 void LIB_EDIT_FRAME::OnRotate( wxCommandEvent& aEvent )
1163 {
1164  LIB_PART* part = GetCurPart();
1166  LIB_ITEM* item = GetDrawItem();
1167 
1168  // Allows block rotate operation on hot key.
1169  if( block.GetState() != STATE_NO_BLOCK )
1170  {
1171  // Compute the rotation center and put it on grid:
1172  wxPoint rotationPoint = block.Centre();
1173  rotationPoint = GetNearestGridPosition( rotationPoint );
1174 
1175  // The Y axis orientation is bottom to top for symbol items.
1176  // so change the Y coord value of the rotation center
1177  rotationPoint.y = -rotationPoint.y;
1178 
1179  if( block.AppendUndo() )
1180  ; // UR_LIBEDIT saves entire state, so no need to append anything more
1181  else
1182  {
1183  SaveCopyInUndoList( part, UR_LIBEDIT );
1184  block.SetAppendUndo();
1185  }
1186 
1187  for( unsigned ii = 0; ii < block.GetCount(); ii++ )
1188  {
1189  item = dynamic_cast<LIB_ITEM*>( block.GetItem( ii ) );
1190  item->Rotate( rotationPoint );
1191  }
1192 
1193  GetCanvas()->CallMouseCapture( nullptr, wxDefaultPosition, false );
1194  GetCanvas()->Refresh();
1195  }
1196  else if( item )
1197  {
1198  wxPoint rotationPoint = item->GetPosition();
1199 
1200  if( !item->InEditMode() )
1201  SaveCopyInUndoList( part, UR_LIBEDIT );
1202 
1203  item->Rotate( rotationPoint );
1204 
1205  if( item->InEditMode() )
1206  GetCanvas()->CallMouseCapture( nullptr, wxDefaultPosition, false );
1207  else
1208  GetCanvas()->GetView()->Update( item );
1209  GetCanvas()->Refresh();
1210  OnModify();
1211 
1212  if( !item->InEditMode() )
1213  item->ClearFlags();
1214 
1215  if( GetToolId() == ID_NO_TOOL_SELECTED )
1216  m_lastDrawItem = NULL;
1217  }
1218 }
1219 
1220 
1221 void LIB_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent )
1222 {
1223  LIB_PART* part = GetCurPart();
1225  LIB_ITEM* item = GetDrawItem();
1226 
1227  // Allows block rotate operation on hot key.
1228  if( block.GetState() != STATE_NO_BLOCK )
1229  {
1230  // Compute the mirror center and put it on grid.
1231  wxPoint mirrorPoint = block.Centre();
1232  mirrorPoint = GetNearestGridPosition( mirrorPoint );
1233 
1234  // The Y axis orientation is bottom to top for symbol items.
1235  // so change the Y coord value of the rotation center
1236  mirrorPoint.y = -mirrorPoint.y;
1237 
1238  if( block.AppendUndo() )
1239  ; // UR_LIBEDIT saves entire state, so no need to append anything more
1240  else
1241  {
1242  SaveCopyInUndoList( part, UR_LIBEDIT );
1243  block.SetAppendUndo();
1244  }
1245 
1246  for( unsigned ii = 0; ii < block.GetCount(); ii++ )
1247  {
1248  item = dynamic_cast<LIB_ITEM*>( block.GetItem( ii ) );
1249 
1250  if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y || aEvent.GetId() == ID_POPUP_MIRROR_Y_BLOCK )
1251  item->MirrorHorizontal( mirrorPoint );
1252  else
1253  item->MirrorVertical( mirrorPoint );
1254  }
1255 
1256  m_canvas->CallMouseCapture( nullptr, wxDefaultPosition, false );
1257  GetCanvas()->Refresh();
1258  }
1259  else if( item )
1260  {
1261  wxPoint mirrorPoint = item->GetPosition();
1262  mirrorPoint.y = -mirrorPoint.y;
1263 
1264  if( !item->InEditMode() )
1265  SaveCopyInUndoList( part, UR_LIBEDIT );
1266 
1267  if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y || aEvent.GetId() == ID_POPUP_MIRROR_Y_BLOCK )
1268  item->MirrorHorizontal( mirrorPoint );
1269  else
1270  item->MirrorVertical( mirrorPoint );
1271 
1272  if( item->InEditMode() )
1273  m_canvas->CallMouseCapture( nullptr, wxDefaultPosition, false );
1274  else
1275  GetCanvas()->GetView()->Update( item );
1276  GetCanvas()->Refresh();
1277  OnModify();
1278 
1279  if( !item->InEditMode() )
1280  item->ClearFlags();
1281 
1282  if( GetToolId() == ID_NO_TOOL_SELECTED )
1283  m_lastDrawItem = NULL;
1284  }
1285 }
1286 
1287 
1289  const KICAD_T aFilterList[] )
1290 {
1291  wxPoint pos;
1292  LIB_PART* part = GetCurPart();
1293 
1294  if( !part )
1295  return NULL;
1296 
1297  LIB_ITEM* item = locateItem( aPosition, aFilterList );
1298 
1299  // If the user aborted the clarification context menu, don't show it again at the
1300  // grid position.
1301  if( !item && m_canvas->GetAbortRequest() )
1302  return NULL;
1303 
1304  pos = GetNearestGridPosition( aPosition );
1305 
1306  if( item == NULL && aPosition != pos )
1307  item = locateItem( pos, aFilterList );
1308 
1309  return item;
1310 }
1311 
1312 
1313 LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aFilterList[] )
1314 {
1315  LIB_PART* part = GetCurPart();
1316 
1317  if( !part )
1318  return NULL;
1319 
1320  LIB_ITEM* item = NULL;
1321 
1322  m_collectedItems.Collect( part->GetDrawItems(), aFilterList, aPosition,
1323  m_unit, m_convert );
1324 
1325  if( m_collectedItems.GetCount() == 0 )
1326  {
1327  ClearMsgPanel();
1328  }
1329  else if( m_collectedItems.GetCount() == 1 )
1330  {
1331  item = m_collectedItems[0];
1332  }
1333  else
1334  {
1335  if( item == NULL )
1336  {
1337  wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS,
1338  "Select item clarification context menu size limit exceeded." );
1339 
1340  wxMenu selectMenu;
1341  AddMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ),
1342  KiBitmap( info_xpm ) );
1343 
1344  selectMenu.AppendSeparator();
1345 
1346  for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ )
1347  {
1348  wxString text = m_collectedItems[i]->GetSelectMenuText( m_UserUnits );
1349  BITMAP_DEF xpm = m_collectedItems[i]->GetMenuImage();
1350 
1351  AddMenuItem( &selectMenu, ID_SELECT_ITEM_START + i, text, KiBitmap( xpm ) );
1352  }
1353 
1354  // Set to NULL in case user aborts the clarification context menu.
1355  SetDrawItem( NULL );
1356  m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected
1357  PopupMenu( &selectMenu );
1359  item = GetDrawItem();
1360  }
1361  }
1362 
1363  if( item )
1364  {
1365  MSG_PANEL_ITEMS items;
1366  item->GetMsgPanelInfo( m_UserUnits, items );
1367  SetMsgPanel( items );
1368  }
1369  else
1370  {
1371  ClearMsgPanel();
1372  }
1373 
1374  return item;
1375 }
1376 
1377 
1378 void LIB_EDIT_FRAME::deleteItem( wxDC* aDC, LIB_ITEM* aItem )
1379 {
1380  if( !aItem )
1381  return;
1382 
1383  m_canvas->CrossHairOff( aDC );
1384 
1385  LIB_PART* part = GetCurPart();
1386 
1387  SaveCopyInUndoList( part );
1388 
1389  if( aItem->Type() == LIB_PIN_T )
1390  {
1391  LIB_PIN* pin = static_cast<LIB_PIN*>( aItem );
1392  wxPoint pos = pin->GetPosition();
1393 
1394  part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC );
1395 
1396  // when pin editing is synchronized, all pins of the same body style are removed:
1397  if( SynchronizePins() )
1398  {
1399  int curr_convert = pin->GetConvert();
1400  LIB_PIN* next_pin = part->GetNextPin();
1401 
1402  while( next_pin != NULL )
1403  {
1404  pin = next_pin;
1405  next_pin = part->GetNextPin( pin );
1406 
1407  if( pin->GetPosition() != pos )
1408  continue;
1409 
1410  if( pin->GetConvert() != curr_convert )
1411  continue;
1412 
1413  part->RemoveDrawItem( pin );
1414  }
1415  }
1416  }
1417  else
1418  {
1419  if( m_canvas->IsMouseCaptured() )
1420  m_canvas->CallEndMouseCapture( aDC );
1421  else
1422  part->RemoveDrawItem( aItem, m_canvas, aDC );
1423  }
1424 
1425  SetDrawItem( NULL );
1426  m_lastDrawItem = NULL;
1427  OnModify();
1428  m_canvas->CrossHairOn( aDC );
1429 
1430  RebuildView();
1431  GetCanvas()->Refresh();
1432 }
1433 
1434 
1436 {
1437  GetScreen()->SetModify();
1438  storeCurrentPart();
1439 
1440  m_treePane->GetLibTree()->Refresh();
1441 }
1442 
1443 
1444 void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent )
1445 {
1446  int id = aEvent.GetId();
1447  int index = id - ID_SELECT_ITEM_START;
1448 
1449  if( (id >= ID_SELECT_ITEM_START && id <= ID_SELECT_ITEM_END)
1450  && (index >= 0 && index < m_collectedItems.GetCount()) )
1451  {
1452  LIB_ITEM* item = m_collectedItems[index];
1453  m_canvas->SetAbortRequest( false );
1454  SetDrawItem( item );
1455  }
1456 }
1457 
1458 
1459 void LIB_EDIT_FRAME::OnOpenPinTable( wxCommandEvent& aEvent )
1460 {
1461  LIB_PART* part = GetCurPart();
1462  SaveCopyInUndoList( part );
1463  SetDrawItem( nullptr );
1464 
1465  DIALOG_LIB_EDIT_PIN_TABLE dlg( this, part );
1466 
1467  if( dlg.ShowModal() == wxID_CANCEL )
1468  return;
1469 
1470  RebuildView();
1471  GetCanvas()->Refresh();
1472  OnModify();
1473 }
1474 
1475 
1477 {
1478  LIB_PART* part = GetCurPart();
1479 
1480  return m_syncPinEdit && part && part->IsMulti() && !part->UnitsLocked();
1481 }
1482 
1483 
1485 {
1486  // This is not the most effecient way to do this because the changed library may not have
1487  // any effect on the schematic symbol links. Since this is not called very often, take the
1488  // hit here rather than the myriad other places (including SCH_SCREEN::Draw()) where it was
1489  // being called.
1490  SCH_SCREENS schematic;
1491 
1492  schematic.UpdateSymbolLinks();
1493  schematic.TestDanglingEnds();
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 ( 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:152
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()
Definition: sch_view.cpp:150
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:181
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:1434
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 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:46
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)
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:157
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.
The common library.
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
void SetAutoPanRequest(bool aEnable)
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:1530
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:772
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
void UpdateSymbolLinks(bool aForce=false)
Initialize or reinitialize the weak reference to the LIB_PART for each SCH_COMPONENT found in the ful...
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
void TestDanglingEnds()
LIB_ITEM * GetCurLibItem() const
Definition: sch_screen.h:197
bool saveAllLibraries(bool aRequireConfirmation)
Definition: libedit.cpp:728
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:519
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)
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:921
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)
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:523
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