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 
73 int LIB_EDIT_FRAME:: m_unit = 1;
74 int LIB_EDIT_FRAME:: m_convert = 1;
76 
77 bool LIB_EDIT_FRAME:: m_showDeMorgan = false;
78 int LIB_EDIT_FRAME:: m_textSize = -1;
79 double LIB_EDIT_FRAME:: m_current_text_angle = TEXT_ANGLE_HORIZ;
80 int LIB_EDIT_FRAME:: m_drawLineWidth = 0;
81 
82 // these values are overridden when reading the config
83 int LIB_EDIT_FRAME:: m_textPinNumDefaultSize = DEFAULTPINNUMSIZE;
84 int LIB_EDIT_FRAME:: m_textPinNameDefaultSize = DEFAULTPINNAMESIZE;
85 int LIB_EDIT_FRAME:: m_defaultPinLength = DEFAULTPINLENGTH;
86 
87 FILL_T LIB_EDIT_FRAME:: m_drawFillStyle = NO_FILL;
88 
89 
90 BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
92  EVT_SIZE( LIB_EDIT_FRAME::OnSize )
93  EVT_ACTIVATE( LIB_EDIT_FRAME::OnActivate )
94 
95  // Actions
111 
112  // Main horizontal toolbar.
126 
128 
129  // Right vertical toolbar.
135 
136  // Left vertical toolbar (option toolbar).
139 
140  // menubar commands
151 
153 
154  // Multiple item selection context menu commands.
156 
158 
159  // Context menu events and commands.
162 
166 
169 
171  LIB_EDIT_FRAME::OnOrient )
172 
173  // Update user interface elements.
174  EVT_UPDATE_UI( wxID_PASTE, LIB_EDIT_FRAME::OnUpdatePaste )
180  EVT_UPDATE_UI( ID_LIBEDIT_CHECK_PART, LIB_EDIT_FRAME::OnUpdateEditingPart )
182  EVT_UPDATE_UI( wxID_UNDO, LIB_EDIT_FRAME::OnUpdateUndo )
183  EVT_UPDATE_UI( wxID_REDO, LIB_EDIT_FRAME::OnUpdateRedo )
184  EVT_UPDATE_UI( ID_LIBEDIT_SYNC_PIN_EDIT, LIB_EDIT_FRAME::OnUpdateSyncPinEdit )
187  EVT_UPDATE_UI( ID_DE_MORGAN_NORMAL_BUTT, LIB_EDIT_FRAME::OnUpdateDeMorganNormal )
188  EVT_UPDATE_UI( ID_DE_MORGAN_CONVERT_BUTT, LIB_EDIT_FRAME::OnUpdateDeMorganConvert )
189  EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, LIB_EDIT_FRAME::OnUpdateSelectTool )
190  EVT_UPDATE_UI( ID_ZOOM_SELECTION, LIB_EDIT_FRAME::OnUpdateSelectTool )
192  LIB_EDIT_FRAME::OnUpdateEditingPart )
195  EVT_UPDATE_UI( ID_MENU_CANVAS_CAIRO, LIB_EDIT_FRAME::OnUpdateSwitchCanvas )
196  EVT_UPDATE_UI( ID_MENU_CANVAS_OPENGL, LIB_EDIT_FRAME::OnUpdateSwitchCanvas )
197 
198 END_EVENT_TABLE()
199 
200 LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
201  SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_LIB_EDITOR, _( "Library Editor" ),
202  wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, LIB_EDIT_FRAME_NAME )
203 {
204  m_showAxis = true; // true to draw axis
205  SetShowDeMorgan( false );
206  m_drawSpecificConvert = true;
207  m_drawSpecificUnit = false;
208  m_hotkeysDescrList = g_Libedit_Hokeys_Descr;
209  m_syncPinEdit = false;
210  m_repeatPinStep = DEFAULT_REPEAT_OFFSET_PIN;
211  SetShowElectricalType( true );
212  m_FrameSize = ConvertDialogToPixels( wxSize( 500, 350 ) ); // default in case of no prefs
213 
214  m_my_part = NULL;
215  m_tempCopyComponent = NULL;
216  m_treePane = nullptr;
217  m_libMgr = nullptr;
218 
219  // Delayed initialization
220  if( m_textSize == -1 )
221  m_textSize = GetDefaultTextSize();
222 
223  // Initialize grid id to the default value 50 mils:
225 
226  wxIcon icon;
227  icon.CopyFromBitmap( KiBitmap( icon_libedit_xpm ) );
228  SetIcon( icon );
229 
230  LoadSettings( config() );
231 
232  m_dummyScreen = new SCH_SCREEN( aKiway );
233  SetScreen( m_dummyScreen );
234  GetScreen()->m_Center = true;
235  GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
236 
237  SetCrossHairPosition( wxPoint( 0, 0 ) );
238 
239  SetPresetGrid( m_LastGridSizeId );
240 
241  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
242 
243  if( m_canvas )
244  m_canvas->SetEnableBlockCommands( true );
245 
246  m_libMgr = new LIB_MANAGER( *this );
247  SyncLibraries( true );
248  m_treePane = new SYMBOL_TREE_PANE( this, m_libMgr );
249 
250  ReCreateMenuBar();
251  ReCreateHToolbar();
252  ReCreateVToolbar();
253  ReCreateOptToolbar();
254 
255  updateTitle();
256  DisplayCmpDoc();
257  UpdatePartSelectList();
258 
259  m_auimgr.SetManagedWindow( this );
260  m_auimgr.SetArtProvider( new EDA_DOCKART( this ) );
261 
262 
263  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
264  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
265 
266  m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) );
267  m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "ComponentTree" ).Left().Layer(1)
268  .Caption( _( "Libraries" ) ).MinSize( 250, -1 )
269  .BestSize( m_defaultLibWidth, -1 ).Resizable() );
270  m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ).Right().Layer(1) );
271 
272  m_auimgr.AddPane( m_canvas->GetWindow(), wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
273 
274  m_auimgr.Update();
275 
276  Raise();
277  Show( true );
278 
279  Bind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnConfigurePaths, this,
281 
282  Bind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnEditSymbolLibTable, this,
284 
285  wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, ID_ZOOM_PAGE );
286  wxPostEvent( this, evt );
287 
288  SyncView();
289  GetGalCanvas()->GetViewControls()->SetSnapping( true );
290  GetGalCanvas()->GetView()->UseDrawPriority( true );
291  GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
292  GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
293 
294  // Set the working/draw area size to display a symbol to a reasonable value:
295  // A 600mm x 600mm with a origin at the area center looks like a large working area
296  double max_size_x = Millimeter2iu( 600 );
297  double max_size_y = Millimeter2iu( 600 );
298  BOX2D bbox;
299  bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
300  bbox.SetSize( max_size_x, max_size_y );
301  GetCanvas()->GetView()->SetBoundary( bbox );
302 }
303 
304 
306 {
307  Unbind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnEditSymbolLibTable, this,
309 
310  // current screen is destroyed in EDA_DRAW_FRAME
312 
313  m_lastDrawItem = NULL;
315 
316  delete m_tempCopyComponent;
317  delete m_libMgr;
318  delete m_my_part;
319 }
320 
321 
322 void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
323 {
324  if( saveAllLibraries( true ) )
325  Destroy();
326  else
327  Event.Veto();
328 }
329 
330 
332 {
333  LIB_PART* part = GetCurPart();
334  double defaultLibraryZoom = 7.33;
335 
336  if( !part )
337  {
338  SetScrollCenterPosition( wxPoint( 0, 0 ) );
339  return defaultLibraryZoom;
340  }
341 
343 
344  double sizeX = (double) boundingBox.GetWidth();
345  double sizeY = (double) boundingBox.GetHeight();
346  wxPoint centre = boundingBox.Centre();
347 
348  // Reserve a 20% margin around component bounding box.
349  double margin_scale_factor = 1.2;
350 
351  return bestZoom( sizeX, sizeY, margin_scale_factor, centre);
352 }
353 
354 
356 {
357  if( m_partSelectBox == NULL )
358  return;
359 
360  if( m_partSelectBox->GetCount() != 0 )
361  m_partSelectBox->Clear();
362 
363  LIB_PART* part = GetCurPart();
364 
365  if( !part || part->GetUnitCount() <= 1 )
366  {
367  m_unit = 1;
368  m_partSelectBox->Append( wxEmptyString );
369  }
370  else
371  {
372  for( int i = 0; i < part->GetUnitCount(); i++ )
373  {
374  wxString sub = LIB_PART::SubReference( i+1, false );
375  wxString unit = wxString::Format( _( "Unit %s" ), GetChars( sub ) );
376  m_partSelectBox->Append( unit );
377  }
378  }
379 
380  // Ensure the current selected unit is compatible with
381  // the number of units of the current part:
382  if( part && part->GetUnitCount() < m_unit )
383  m_unit = 1;
384 
385  m_partSelectBox->SetSelection( ( m_unit > 0 ) ? m_unit - 1 : 0 );
386 }
387 
388 
389 void LIB_EDIT_FRAME::OnShowElectricalType( wxCommandEvent& event )
390 {
392 
393  // Update canvas
396  GetCanvas()->Refresh();
397 }
398 
399 
400 void LIB_EDIT_FRAME::OnToggleSearchTree( wxCommandEvent& event )
401 {
402  auto& treePane = m_auimgr.GetPane( m_treePane );
403  treePane.Show( !IsSearchTreeShown() );
404  m_auimgr.Update();
405 }
406 
407 
408 void LIB_EDIT_FRAME::OnEditSymbolLibTable( wxCommandEvent& aEvent )
409 {
410  m_libMgr->GetAdapter()->Freeze();
411 
413  SyncLibraries( true );
414 
415  m_libMgr->GetAdapter()->Thaw();
416 }
417 
418 
420 {
421  return m_auimgr.GetPane( m_treePane ).IsShown();
422 }
423 
424 
426 {
428 }
429 
430 
431 void LIB_EDIT_FRAME::OnUpdateSelectTool( wxUpdateUIEvent& aEvent )
432 {
433  if( aEvent.GetEventObject() == m_drawToolBar || aEvent.GetEventObject() == m_mainToolBar )
434  aEvent.Check( GetToolId() == aEvent.GetId() );
435 }
436 
437 
438 void LIB_EDIT_FRAME::OnUpdateElectricalType( wxUpdateUIEvent& aEvent )
439 {
440  aEvent.Check( GetShowElectricalType() );
441 }
442 
443 
444 void LIB_EDIT_FRAME::OnUpdateSearchTreeTool( wxUpdateUIEvent& aEvent )
445 {
446  aEvent.Check( IsSearchTreeShown() );
447 }
448 
449 
450 void LIB_EDIT_FRAME::OnUpdateSave( wxUpdateUIEvent& aEvent )
451 {
452  LIB_ID libId = getTargetLibId();
453  const wxString& libName = libId.GetLibNickname();
454  const wxString& partName = libId.GetLibItemName();
455  bool readOnly = libName.IsEmpty() || m_libMgr->IsLibraryReadOnly( libName );
456 
457  if( partName.IsEmpty() )
458  aEvent.Enable( !readOnly && m_libMgr->IsLibraryModified( libName ) );
459  else
460  aEvent.Enable( !readOnly && m_libMgr->IsPartModified( partName, libName ) );
461 }
462 
463 
464 void LIB_EDIT_FRAME::OnUpdateSaveAs( wxUpdateUIEvent& aEvent )
465 {
466  LIB_ID libId = getTargetLibId();
467  const wxString& libName = libId.GetLibNickname();
468  const wxString& partName = libId.GetLibItemName();
469 
470  aEvent.Enable( !libName.IsEmpty() || !partName.IsEmpty() );
471 }
472 
473 
474 void LIB_EDIT_FRAME::OnUpdateRevert( wxUpdateUIEvent& aEvent )
475 {
476  LIB_ID libId = getTargetLibId();
477  const wxString& libName = libId.GetLibNickname();
478  const wxString& partName = libId.GetLibItemName();
479 
480  if( partName.IsEmpty() )
481  aEvent.Enable( !libName.IsEmpty() && m_libMgr->IsLibraryModified( libName ) );
482  else
483  aEvent.Enable( !libName.IsEmpty() && m_libMgr->IsPartModified( partName, libName ) );
484 }
485 
486 
487 void LIB_EDIT_FRAME::OnUpdateHavePart( wxUpdateUIEvent& aEvent )
488 {
489  aEvent.Enable( getTargetLibId().IsValid() );
490 }
491 
492 
493 void LIB_EDIT_FRAME::OnUpdateEditingPart( wxUpdateUIEvent& aEvent )
494 {
495  LIB_PART* part = GetCurPart();
496 
497  aEvent.Enable( part != NULL );
498 
499  if( part && aEvent.GetEventObject() == m_drawToolBar )
500  aEvent.Check( GetToolId() == aEvent.GetId() );
501 }
502 
503 
504 void LIB_EDIT_FRAME::OnUpdatePaste( wxUpdateUIEvent& event )
505 {
506  event.Enable( m_clipboard.GetCount() > 0 );
507 }
508 
509 
510 void LIB_EDIT_FRAME::OnUpdateUndo( wxUpdateUIEvent& event )
511 {
512  event.Enable( GetCurPart() && GetScreen() &&
513  GetScreen()->GetUndoCommandCount() != 0 && !IsEditingDrawItem() );
514 }
515 
516 
517 void LIB_EDIT_FRAME::OnUpdateRedo( wxUpdateUIEvent& event )
518 {
519  event.Enable( GetCurPart() && GetScreen() &&
520  GetScreen()->GetRedoCommandCount() != 0 && !IsEditingDrawItem() );
521 }
522 
523 
524 void LIB_EDIT_FRAME::OnUpdateSyncPinEdit( wxUpdateUIEvent& event )
525 {
526  LIB_PART* part = GetCurPart();
527  event.Enable( part && part->IsMulti() && !part->UnitsLocked() );
528  event.Check( m_syncPinEdit );
529 }
530 
531 
532 void LIB_EDIT_FRAME::OnUpdatePinTable( wxUpdateUIEvent& event )
533 {
534  LIB_PART* part = GetCurPart();
535  event.Enable( part != NULL );
536 }
537 
538 
539 void LIB_EDIT_FRAME::OnUpdatePartNumber( wxUpdateUIEvent& event )
540 {
541  if( m_partSelectBox == NULL )
542  return;
543 
544  LIB_PART* part = GetCurPart();
545 
546  // Using the typical event.Enable() call doesn't seem to work with wxGTK
547  // so use the pointer to alias combobox to directly enable or disable.
548  m_partSelectBox->Enable( part && part->GetUnitCount() > 1 );
549 }
550 
551 
552 void LIB_EDIT_FRAME::OnUpdateDeMorganNormal( wxUpdateUIEvent& event )
553 {
554  if( m_mainToolBar == NULL )
555  return;
556 
557  LIB_PART* part = GetCurPart();
558 
559  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
560  event.Check( m_convert <= 1 );
561 }
562 
563 
564 void LIB_EDIT_FRAME::OnUpdateDeMorganConvert( wxUpdateUIEvent& event )
565 {
566  if( m_mainToolBar == NULL )
567  return;
568 
569  LIB_PART* part = GetCurPart();
570 
571  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
572  event.Check( m_convert > 1 );
573 }
574 
575 
576 void LIB_EDIT_FRAME::OnSelectPart( wxCommandEvent& event )
577 {
578  int i = event.GetSelection();
579 
580  if( ( i == wxNOT_FOUND ) || ( ( i + 1 ) == m_unit ) )
581  return;
582 
583  m_lastDrawItem = NULL;
584  m_unit = i + 1;
585 
586  RebuildView();
587  DisplayCmpDoc();
588 }
589 
590 
591 void LIB_EDIT_FRAME::OnViewEntryDoc( wxCommandEvent& event )
592 {
593  LIB_PART* part = GetCurPart();
594 
595  if( !part )
596  return;
597 
598  wxString filename;
599 
600  if( part->GetAliasCount() > 1 )
601  {
602  CONTEXT_MENU popup;
603  wxString msg;
604  int id = 0;
605 
606  for( LIB_ALIAS* alias : part->GetAliases() )
607  {
608  msg.Printf( wxT( "%s (%s)" ), alias->GetName(), alias->GetDocFileName() );
609  popup.Append( id++, msg );
610  }
611 
612  PopupMenu( &popup );
613 
614  if( popup.GetSelected() >= 0 )
615  filename = part->GetAlias( (unsigned) popup.GetSelected() )->GetDocFileName();
616  }
617  else
618  filename = part->GetAlias( 0 )->GetDocFileName();
619 
620  if( !filename.IsEmpty() && filename != wxT( "~" ) )
621  {
622  SEARCH_STACK* lib_search = Prj().SchSearchS();
623 
624  GetAssociatedDocument( this, filename, lib_search );
625  }
626 }
627 
628 
629 void LIB_EDIT_FRAME::OnSelectBodyStyle( wxCommandEvent& event )
630 {
631  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
632 
633  if( event.GetId() == ID_DE_MORGAN_NORMAL_BUTT )
634  m_convert = 1;
635  else
636  m_convert = 2;
637 
638  m_lastDrawItem = NULL;
639 
640  RebuildView();
641 }
642 
643 
644 void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
645 {
646  int id = event.GetId();
647  wxPoint pos;
648  SCH_SCREEN* screen = GetScreen();
650  LIB_ITEM* item = screen->GetCurLibItem();
651 
653 
654  wxGetMousePosition( &pos.x, &pos.y );
655  pos.y += 20;
656 
657  switch( id ) // Stop placement commands before handling new command.
658  {
659  case wxID_COPY:
660  case ID_POPUP_COPY_BLOCK:
661  case wxID_CUT:
662  case ID_POPUP_CUT_BLOCK:
664  case ID_LIBEDIT_EDIT_PIN:
670  case ID_POPUP_ZOOM_BLOCK:
679  break;
680 
682  if( m_canvas->IsMouseCaptured() )
684  else
685  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
686  break;
687 
690  break;
691 
692  default:
693  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor(),
694  wxEmptyString );
695  break;
696  }
697 
698  switch( id )
699  {
701  break;
702 
705  break;
706 
709  if( item )
710  {
711  EndDrawGraphicItem( nullptr );
712  }
713  break;
714 
716  if( item )
717  {
719 
720  switch( item->Type() )
721  {
722  case LIB_ARC_T:
723  case LIB_CIRCLE_T:
724  case LIB_RECTANGLE_T:
725  case LIB_POLYLINE_T:
726  EditGraphicSymbol( nullptr, item );
727  break;
728 
729  case LIB_TEXT_T:
730  EditSymbolText( nullptr, item );
731  break;
732 
733  default:
734  ;
735  }
736 
737  m_canvas->CrossHairOn( );
738  }
739  break;
740 
742  {
743  // Delete the last created segment, while creating a polyline draw item
744  if( item == NULL )
745  break;
746 
748  STATUS_FLAGS oldFlags = item->GetFlags();
749  item->ClearFlags();
750  /* item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
751  DefaultTransform );
752  ( (LIB_POLYLINE*) item )->DeleteSegment( GetCrossHairPosition( true ) );
753  item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
754  DefaultTransform );*/
755  item->SetFlags( oldFlags );
756  m_lastDrawItem = NULL;
757  }
758  break;
759 
761  if( item )
762  deleteItem( nullptr, item );
763 
764  break;
765 
767  if( item == NULL )
768  break;
769 
770  if( item->Type() == LIB_PIN_T )
771  {
772  StartMovePin( item );
773  }
774  else
775  {
776  StartMoveDrawSymbol( nullptr, item );
777  }
778  break;
779 
781 
782  if( item == NULL )
783  break;
784 
786  if( item->Type() == LIB_RECTANGLE_T
787  || item->Type() == LIB_CIRCLE_T
788  || item->Type() == LIB_POLYLINE_T
789  || item->Type() == LIB_ARC_T
790  )
791  {
792  StartModifyDrawSymbol( nullptr, item );
793  }
794 
795  break;
796 
798  if( item == NULL )
799  break;
800 
801  m_canvas->CrossHairOff( nullptr );
802 
803  if( item->Type() == LIB_FIELD_T )
804  {
805  EditField( (LIB_FIELD*) item );
806  }
807 
809  m_canvas->CrossHairOn( );
810  break;
811 
815  {
816  if( !item || item->Type() != LIB_PIN_T )
817  break;
818 
819  LIB_PART* part = GetCurPart();
820 
821  SaveCopyInUndoList( part );
822 
823  GlobalSetPins( (LIB_PIN*) item, id );
825  }
826  break;
827 
828  case ID_POPUP_ZOOM_BLOCK:
829  m_canvas->SetAutoPanRequest( false );
830  block.SetCommand( BLOCK_ZOOM );
831  HandleBlockEnd( nullptr );
832  break;
833 
835  m_canvas->SetAutoPanRequest( false );
836  block.SetCommand( BLOCK_DELETE );
838  HandleBlockEnd( nullptr );
839  break;
840 
842  m_canvas->SetAutoPanRequest( false );
843  block.SetCommand( BLOCK_DUPLICATE );
845  HandleBlockEnd( nullptr );
846  break;
847 
849  m_canvas->SetAutoPanRequest( false );
850  block.SetCommand( BLOCK_SELECT_ITEMS_ONLY );
852  HandleBlockEnd( nullptr );
853  break;
854 
857  OnOrient( event );
858  break;
859 
861  OnRotate( event );
862  break;
863 
865  m_canvas->SetAutoPanRequest( false );
867  HandleBlockPlace( nullptr );
868  break;
869 
870  case wxID_COPY:
871  case ID_POPUP_COPY_BLOCK:
872  block.SetCommand( BLOCK_COPY );
873  block.SetMessageBlock( this );
874  HandleBlockEnd( nullptr );
875  break;
876 
877  case wxID_PASTE:
880  break;
881 
882  case wxID_CUT:
883  case ID_POPUP_CUT_BLOCK:
884  if( block.GetCommand() != BLOCK_MOVE )
885  break;
886 
887  block.SetCommand( BLOCK_CUT );
888  block.SetMessageBlock( this );
889  HandleBlockEnd( nullptr );
890  break;
891 
892  default:
893  wxFAIL_MSG( "LIB_EDIT_FRAME::Process_Special_Functions error" );
894  break;
895  }
896 
897  m_canvas->SetIgnoreMouseEvents( false );
898 
899  if( GetToolId() == ID_NO_TOOL_SELECTED )
900  m_lastDrawItem = NULL;
901 }
902 
903 
904 void LIB_EDIT_FRAME::OnActivate( wxActivateEvent& event )
905 {
907 }
908 
909 
911 {
912  wxString libNickname = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_LIB );
913 
914  if( !libNickname.empty() )
915  {
916  if( !Prj().SchSymbolLibTable()->HasLibrary( libNickname ) )
917  {
918  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
919  libNickname = wxEmptyString;
920  }
921  }
922 
923  return libNickname;
924 }
925 
926 
927 wxString LIB_EDIT_FRAME::SetCurLib( const wxString& aLibNickname )
928 {
929  wxString old = GetCurLib();
930 
931  if( aLibNickname.empty() || !Prj().SchSymbolLibTable()->HasLibrary( aLibNickname ) )
932  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
933  else
934  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, aLibNickname );
935 
936  m_libMgr->SetCurrentLib( aLibNickname );
937 
938  return old;
939 }
940 
941 
943 {
944  if( !aPart && !m_my_part )
945  return;
946 
947  GetScreen()->SetCurItem( nullptr );
948 
949  if( m_my_part != aPart )
950  {
951  if( m_my_part )
952  delete m_my_part;
953 
954  m_my_part = aPart;
955  }
956 
957  // select the current component in the tree widget
958  if( aPart )
959  m_treePane->GetLibTree()->SelectLibId( aPart->GetLibId() );
960 
961  wxString partName = aPart ? aPart->GetName() : wxString();
962  m_libMgr->SetCurrentPart( partName );
963 
964  // retain in case this wxFrame is re-opened later on the same PROJECT
966 
967  // Ensure synchronized pin edit can be enabled only symbols with interchangeable units
968  m_syncPinEdit = aPart && aPart->IsMulti() && !aPart->UnitsLocked();
969 
970  RebuildView();
971 }
972 
973 
975 {
976  delete m_tempCopyComponent;
977 
978  if( LIB_PART* part = GetCurPart() )
979  // clone it and own the clone.
980  m_tempCopyComponent = new LIB_PART( *part );
981  else
982  // clear it, there was no CurPart
983  m_tempCopyComponent = NULL;
984 }
985 
986 
988 {
989  if( m_tempCopyComponent )
990  {
991  // transfer ownership to CurPart
993  m_tempCopyComponent = NULL;
994  }
995 }
996 
997 
999 {
1000  delete m_tempCopyComponent;
1001  m_tempCopyComponent = NULL;
1002 }
1003 
1004 
1005 void LIB_EDIT_FRAME::EditSymbolText( wxDC* DC, LIB_ITEM* DrawItem )
1006 {
1007  if ( ( DrawItem == NULL ) || ( DrawItem->Type() != LIB_TEXT_T ) )
1008  return;
1009 
1010  // Deleting old text
1011  if( DC && !DrawItem->InEditMode() )
1012  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
1013  DefaultTransform );
1014 
1015  DIALOG_LIB_EDIT_TEXT dlg( this, (LIB_TEXT*) DrawItem );
1016 
1017  if( dlg.ShowModal() != wxID_OK )
1018  return;
1019 
1020  GetCanvas()->GetView()->Update( DrawItem );
1021  GetCanvas()->Refresh();
1022  OnModify();
1023 
1024  // Display new text
1025  if( DC && !DrawItem->InEditMode() )
1026  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, GR_DEFAULT_DRAWMODE,
1027  NULL, DefaultTransform );
1028 }
1029 
1030 
1031 void LIB_EDIT_FRAME::OnEditComponentProperties( wxCommandEvent& event )
1032 {
1033  bool partLocked = GetCurPart()->UnitsLocked();
1034  wxString oldName = GetCurPart()->GetName();
1035  wxArrayString oldAliases = GetCurPart()->GetAliasNames( false );
1036 
1037  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
1038 
1039  if( GetDrawItem() && GetDrawItem()->Type() == LIB_FIELD_T )
1040  SetDrawItem( nullptr ); // selected LIB_FIELD might be deleted
1041 
1043 
1044  // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
1045  // frame. Therefore this dialog as a modal frame parent, MUST be run under
1046  // quasimodal mode for the quasimodal frame support to work. So don't use
1047  // the QUASIMODAL macros here.
1048  if( dlg.ShowQuasiModal() != wxID_OK )
1049  return;
1050 
1051  // if m_UnitSelectionLocked has changed, set some edit options or defaults
1052  // to the best value
1053  if( partLocked != GetCurPart()->UnitsLocked() )
1054  {
1055  // Enable synchronized pin edit mode for symbols with interchangeable units
1057  // also set default edit options to the better value
1058  // Usually if units are locked, graphic items are specific to each unit
1059  // and if units are interchangeable, graphic items are common to units
1061  }
1062 
1063  if( oldName != GetCurPart()->GetName() )
1065  else
1066  {
1068 
1069  if( oldAliases != GetCurPart()->GetAliasNames( false ) )
1070  SyncLibraries( false );
1071  }
1072 
1074  updateTitle();
1075  DisplayCmpDoc();
1076 
1077  RebuildView();
1078  GetCanvas()->Refresh();
1079  OnModify();
1080 }
1081 
1082 
1083 void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
1084 {
1085  int id = aEvent.GetId();
1086  int lastToolID = GetToolId();
1087 
1089  m_lastDrawItem = NULL;
1090 
1091  // Stop the current command and deselect the current tool.
1092  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() );
1093 
1094  LIB_PART* part = GetCurPart();
1095 
1096  switch( id )
1097  {
1098  case ID_NO_TOOL_SELECTED:
1099  SetToolID( id, GetGalCanvas()->GetDefaultCursor(), wxEmptyString );
1100  break;
1101 
1103  case ID_ZOOM_SELECTION:
1104  // This tool is located on the main toolbar: switch it on or off on click on it
1105  if( lastToolID != ID_ZOOM_SELECTION )
1106  SetToolID( ID_ZOOM_SELECTION, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) );
1107  else
1109  break;
1110 
1111  case ID_LIBEDIT_PIN_BUTT:
1112  if( part )
1113  {
1114  SetToolID( id, wxCURSOR_PENCIL, _( "Add pin" ) );
1115  }
1116  else
1117  {
1118  SetToolID( id, wxCURSOR_ARROW, _( "Set pin options" ) );
1119 
1120  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
1121 
1122  cmd.SetId( ID_LIBEDIT_EDIT_PIN );
1123  GetEventHandler()->ProcessEvent( cmd );
1125  }
1126  break;
1127 
1129  SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) );
1130  break;
1131 
1133  SetToolID( id, wxCURSOR_PENCIL, _( "Add rectangle" ) );
1134  break;
1135 
1137  SetToolID( id, wxCURSOR_PENCIL, _( "Add circle" ) );
1138  break;
1139 
1141  SetToolID( id, wxCURSOR_PENCIL, _( "Add arc" ) );
1142  break;
1143 
1145  SetToolID( id, wxCURSOR_PENCIL, _( "Add line" ) );
1146  break;
1147 
1149  SetToolID( id, wxCURSOR_HAND, _( "Set anchor position" ) );
1150  break;
1151 
1153  SetToolID( id, GetGalCanvas()->GetDefaultCursor(), _( "Import" ) );
1154  LoadOneSymbol();
1156  break;
1157 
1159  SetToolID( id, GetGalCanvas()->GetDefaultCursor(), _( "Export" ) );
1160  SaveOneSymbol();
1162  break;
1163 
1165  if( !part )
1166  {
1167  wxBell();
1168  break;
1169  }
1170 
1171  SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
1172  break;
1173 
1174  default:
1175  break;
1176  }
1177 
1178  m_canvas->SetIgnoreMouseEvents( false );
1179 }
1180 
1181 
1182 void LIB_EDIT_FRAME::OnRotate( wxCommandEvent& aEvent )
1183 {
1184  LIB_PART* part = GetCurPart();
1186  LIB_ITEM* item = GetDrawItem();
1187 
1188  // Allows block rotate operation on hot key.
1189  if( block.GetState() != STATE_NO_BLOCK )
1190  {
1191  // Compute the rotation center and put it on grid:
1192  wxPoint rotationPoint = block.Centre();
1193  rotationPoint = GetNearestGridPosition( rotationPoint );
1194 
1195  // The Y axis orientation is bottom to top for symbol items.
1196  // so change the Y coord value of the rotation center
1197  rotationPoint.y = -rotationPoint.y;
1198 
1199  if( block.AppendUndo() )
1200  ; // UR_LIBEDIT saves entire state, so no need to append anything more
1201  else
1202  {
1203  SaveCopyInUndoList( part, UR_LIBEDIT );
1204  block.SetAppendUndo();
1205  }
1206 
1207  for( unsigned ii = 0; ii < block.GetCount(); ii++ )
1208  {
1209  item = static_cast<LIB_ITEM*>( block.GetItem( ii ) );
1210  item->Rotate( rotationPoint );
1211  }
1212 
1213  GetCanvas()->CallMouseCapture( nullptr, wxDefaultPosition, false );
1214  GetCanvas()->Refresh();
1215  }
1216  else if( item )
1217  {
1218  wxPoint rotationPoint = item->GetPosition();
1219 
1220  if( !item->InEditMode() )
1221  SaveCopyInUndoList( part, UR_LIBEDIT );
1222 
1223  item->Rotate( rotationPoint );
1224 
1225  if( item->InEditMode() )
1226  GetCanvas()->CallMouseCapture( nullptr, wxDefaultPosition, false );
1227  else
1228  GetCanvas()->GetView()->Update( item );
1229  GetCanvas()->Refresh();
1230  OnModify();
1231 
1232  if( !item->InEditMode() )
1233  item->ClearFlags();
1234 
1235  if( GetToolId() == ID_NO_TOOL_SELECTED )
1236  m_lastDrawItem = NULL;
1237  }
1238 }
1239 
1240 
1241 void LIB_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent )
1242 {
1243  LIB_PART* part = GetCurPart();
1245  LIB_ITEM* item = GetDrawItem();
1246 
1247  // Allows block rotate operation on hot key.
1248  if( block.GetState() != STATE_NO_BLOCK )
1249  {
1250  // Compute the mirror center and put it on grid.
1251  wxPoint mirrorPoint = block.Centre();
1252  mirrorPoint = GetNearestGridPosition( mirrorPoint );
1253 
1254  // The Y axis orientation is bottom to top for symbol items.
1255  // so change the Y coord value of the rotation center
1256  mirrorPoint.y = -mirrorPoint.y;
1257 
1258  if( block.AppendUndo() )
1259  ; // UR_LIBEDIT saves entire state, so no need to append anything more
1260  else
1261  {
1262  SaveCopyInUndoList( part, UR_LIBEDIT );
1263  block.SetAppendUndo();
1264  }
1265 
1266  for( unsigned ii = 0; ii < block.GetCount(); ii++ )
1267  {
1268  item = static_cast<LIB_ITEM*>( block.GetItem( ii ) );
1269 
1270  if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y || aEvent.GetId() == ID_POPUP_MIRROR_Y_BLOCK )
1271  item->MirrorHorizontal( mirrorPoint );
1272  else
1273  item->MirrorVertical( mirrorPoint );
1274  }
1275 
1276  m_canvas->CallMouseCapture( nullptr, wxDefaultPosition, false );
1277  GetCanvas()->Refresh();
1278  }
1279  else if( item )
1280  {
1281  wxPoint mirrorPoint = item->GetPosition();
1282  mirrorPoint.y = -mirrorPoint.y;
1283 
1284  if( !item->InEditMode() )
1285  SaveCopyInUndoList( part, UR_LIBEDIT );
1286 
1287  if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y || aEvent.GetId() == ID_POPUP_MIRROR_Y_BLOCK )
1288  item->MirrorHorizontal( mirrorPoint );
1289  else
1290  item->MirrorVertical( mirrorPoint );
1291 
1292  if( item->InEditMode() )
1293  m_canvas->CallMouseCapture( nullptr, wxDefaultPosition, false );
1294  else
1295  GetCanvas()->GetView()->Update( item );
1296  GetCanvas()->Refresh();
1297  OnModify();
1298 
1299  if( !item->InEditMode() )
1300  item->ClearFlags();
1301 
1302  if( GetToolId() == ID_NO_TOOL_SELECTED )
1303  m_lastDrawItem = NULL;
1304  }
1305 }
1306 
1307 
1309  const KICAD_T aFilterList[] )
1310 {
1311  wxPoint pos;
1312  LIB_PART* part = GetCurPart();
1313 
1314  if( !part )
1315  return NULL;
1316 
1317  LIB_ITEM* item = locateItem( aPosition, aFilterList );
1318 
1319  // If the user aborted the clarification context menu, don't show it again at the
1320  // grid position.
1321  if( !item && m_canvas->GetAbortRequest() )
1322  return NULL;
1323 
1324  pos = GetNearestGridPosition( aPosition );
1325 
1326  if( item == NULL && aPosition != pos )
1327  item = locateItem( pos, aFilterList );
1328 
1329  return item;
1330 }
1331 
1332 
1333 LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aFilterList[] )
1334 {
1335  LIB_PART* part = GetCurPart();
1336 
1337  if( !part )
1338  return NULL;
1339 
1340  LIB_ITEM* item = NULL;
1341 
1342  m_collectedItems.Collect( part->GetDrawItems(), aFilterList, aPosition,
1343  m_unit, m_convert );
1344 
1345  if( m_collectedItems.GetCount() == 0 )
1346  {
1347  ClearMsgPanel();
1348  }
1349  else if( m_collectedItems.GetCount() == 1 )
1350  {
1351  item = m_collectedItems[0];
1352  }
1353  else
1354  {
1355  if( item == NULL )
1356  {
1357  wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS,
1358  "Select item clarification context menu size limit exceeded." );
1359 
1360  wxMenu selectMenu;
1361  AddMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ),
1362  KiBitmap( info_xpm ) );
1363 
1364  selectMenu.AppendSeparator();
1365 
1366  for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ )
1367  {
1368  wxString text = m_collectedItems[i]->GetSelectMenuText( m_UserUnits );
1369  BITMAP_DEF xpm = m_collectedItems[i]->GetMenuImage();
1370 
1371  AddMenuItem( &selectMenu, ID_SELECT_ITEM_START + i, text, KiBitmap( xpm ) );
1372  }
1373 
1374  // Set to NULL in case user aborts the clarification context menu.
1375  SetDrawItem( NULL );
1376  m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected
1377  PopupMenu( &selectMenu );
1379  item = GetDrawItem();
1380  }
1381  }
1382 
1383  if( item )
1384  {
1385  MSG_PANEL_ITEMS items;
1386  item->GetMsgPanelInfo( m_UserUnits, items );
1387  SetMsgPanel( items );
1388  }
1389  else
1390  {
1391  ClearMsgPanel();
1392  }
1393 
1394  return item;
1395 }
1396 
1397 
1398 void LIB_EDIT_FRAME::deleteItem( wxDC* aDC, LIB_ITEM* aItem )
1399 {
1400  if( !aItem )
1401  return;
1402 
1403  m_canvas->CrossHairOff( aDC );
1404 
1405  LIB_PART* part = GetCurPart();
1406 
1407  SaveCopyInUndoList( part );
1408 
1409  if( aItem->Type() == LIB_PIN_T )
1410  {
1411  LIB_PIN* pin = static_cast<LIB_PIN*>( aItem );
1412  wxPoint pos = pin->GetPosition();
1413 
1414  part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC );
1415 
1416  // when pin editing is synchronized, all pins of the same body style are removed:
1417  if( SynchronizePins() )
1418  {
1419  int curr_convert = pin->GetConvert();
1420  LIB_PIN* next_pin = part->GetNextPin();
1421 
1422  while( next_pin != NULL )
1423  {
1424  pin = next_pin;
1425  next_pin = part->GetNextPin( pin );
1426 
1427  if( pin->GetPosition() != pos )
1428  continue;
1429 
1430  if( pin->GetConvert() != curr_convert )
1431  continue;
1432 
1433  part->RemoveDrawItem( pin );
1434  }
1435  }
1436  }
1437  else
1438  {
1439  if( m_canvas->IsMouseCaptured() )
1440  m_canvas->CallEndMouseCapture( aDC );
1441  else
1442  part->RemoveDrawItem( aItem, m_canvas, aDC );
1443  }
1444 
1445  SetDrawItem( NULL );
1446  m_lastDrawItem = NULL;
1447  OnModify();
1448  m_canvas->CrossHairOn( aDC );
1449 
1450  RebuildView();
1451  GetCanvas()->Refresh();
1452 }
1453 
1454 
1456 {
1457  GetScreen()->SetModify();
1458  storeCurrentPart();
1459 
1460  m_treePane->GetLibTree()->Refresh();
1461 }
1462 
1463 
1464 void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent )
1465 {
1466  int id = aEvent.GetId();
1467  int index = id - ID_SELECT_ITEM_START;
1468 
1469  if( (id >= ID_SELECT_ITEM_START && id <= ID_SELECT_ITEM_END)
1470  && (index >= 0 && index < m_collectedItems.GetCount()) )
1471  {
1472  LIB_ITEM* item = m_collectedItems[index];
1473  m_canvas->SetAbortRequest( false );
1474  SetDrawItem( item );
1475  }
1476 }
1477 
1478 
1479 void LIB_EDIT_FRAME::OnOpenPinTable( wxCommandEvent& aEvent )
1480 {
1481  LIB_PART* part = GetCurPart();
1482  SaveCopyInUndoList( part );
1483  SetDrawItem( nullptr );
1484 
1485  DIALOG_LIB_EDIT_PIN_TABLE dlg( this, part );
1486 
1487  if( dlg.ShowModal() == wxID_CANCEL )
1488  return;
1489 
1490  RebuildView();
1491  GetCanvas()->Refresh();
1492  OnModify();
1493 }
1494 
1495 
1497 {
1498  LIB_PART* part = GetCurPart();
1499 
1500  return m_syncPinEdit && part && part->IsMulti() && !part->UnitsLocked();
1501 }
1502 
1503 
1505 {
1506  // There may be no parent window so use KIWAY message to refresh the schematic editor
1507  // in case any symbols have changed.
1508  Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_REFRESH, std::string( "" ), this );
1509 }
1510 
1511 
1512 bool LIB_EDIT_FRAME::addLibraryFile( bool aCreateNew )
1513 {
1514  wxFileName fn = m_libMgr->GetUniqueLibraryName();
1515 
1516  if( !LibraryFileBrowser( !aCreateNew, fn,
1518  false ) )
1519  {
1520  return false;
1521  }
1522 
1523  wxString libName = fn.GetName();
1524 
1525  if( libName.IsEmpty() )
1526  return false;
1527 
1528  if( m_libMgr->LibraryExists( libName ) )
1529  {
1530  DisplayError( this, wxString::Format( _( "Library \"%s\" already exists" ), libName ) );
1531  return false;
1532  }
1533 
1534  // Select the target library table (global/project)
1535  SYMBOL_LIB_TABLE* libTable = selectSymLibTable();
1536 
1537  if( !libTable )
1538  return false;
1539 
1540  if( aCreateNew )
1541  {
1542  if( !m_libMgr->CreateLibrary( fn.GetFullPath(), libTable ) )
1543  {
1544  DisplayError( this, _( "Could not create the library file. Check write permission." ) );
1545  return false;
1546  }
1547  }
1548  else
1549  {
1550  if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
1551  {
1552  DisplayError( this, _( "Could not open the library file." ) );
1553  return false;
1554  }
1555  }
1556 
1557  bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
1558  saveSymbolLibTables( globalTable, !globalTable );
1559 
1560  return true;
1561 }
1562 
1563 
1565 {
1566  LIB_ALIAS* alias = nullptr;
1567 
1568  if( m_treePane->GetLibTree()->IsMenuActive() )
1569  {
1571  alias = m_libMgr->GetAlias( libId.GetLibItemName(), libId.GetLibNickname() );
1572  }
1573  else if( LIB_PART* part = GetCurPart() )
1574  {
1575  alias = part->GetAlias( 0 );
1576  }
1577 
1578  return alias ? alias->GetPart() : nullptr;
1579 }
1580 
1581 
1583 {
1585  wxString nickname = id.GetLibNickname();
1586 
1587  if( nickname.IsEmpty() && GetCurPart() )
1588  id = GetCurPart()->GetLibId();
1589 
1590  return id;
1591 }
1592 
1593 
1595 {
1596  return getTargetLibId().GetLibNickname();
1597 }
1598 
1599 
1600 void LIB_EDIT_FRAME::SyncLibraries( bool aShowProgress )
1601 {
1602  LIB_ID selected;
1603 
1604  if( m_treePane )
1605  selected = m_treePane->GetLibTree()->GetSelectedLibId();
1606 
1607  if( aShowProgress )
1608  {
1609  wxProgressDialog progressDlg( _( "Loading Symbol Libraries" ), wxEmptyString,
1610  m_libMgr->GetAdapter()->GetLibrariesCount(), this );
1611 
1612  m_libMgr->Sync( true, [&]( int progress, int max, const wxString& libName )
1613  {
1614  progressDlg.Update( progress, wxString::Format( _( "Loading library \"%s\"" ), libName ) );
1615  } );
1616  }
1617  else
1618  {
1619  m_libMgr->Sync( true );
1620  }
1621 
1622  if( m_treePane )
1623  {
1624  wxDataViewItem found;
1625 
1626  if( selected.IsValid() )
1627  {
1628  // Check if the previously selected item is still valid,
1629  // if not - it has to be unselected to prevent crash
1630  found = m_libMgr->GetAdapter()->FindItem( selected );
1631 
1632  if( !found )
1634  }
1635 
1637 
1638  // Try to select the parent library, in case the part is not found
1639  if( !found && selected.IsValid() )
1640  {
1641  selected.SetLibItemName( "" );
1642  found = m_libMgr->GetAdapter()->FindItem( selected );
1643 
1644  if( found )
1645  m_treePane->GetLibTree()->SelectLibId( selected );
1646  }
1647 
1648  // If no selection, see if there's a current part to centre
1649  if( !selected.IsValid() && GetCurPart() )
1650  {
1651  LIB_ID current( GetCurLib(), GetCurPart()->GetName() );
1652  m_treePane->GetLibTree()->CenterLibId( current );
1653  }
1654  }
1655 }
1656 
1657 
1659 {
1660  wxArrayString libTableNames;
1661  libTableNames.Add( _( "Global" ) );
1662  libTableNames.Add( _( "Project" ) );
1663 
1664  wxSingleChoiceDialog dlg( this, _( "Choose the Library Table to add the library to:" ),
1665  _( "Add To Library Table" ), libTableNames );
1666 
1667  if( aOptional )
1668  {
1669  dlg.FindWindow( wxID_CANCEL )->SetLabel( _( "Skip" ) );
1670  dlg.FindWindow( wxID_OK )->SetLabel( _( "Add" ) );
1671  }
1672 
1673  if( dlg.ShowModal() != wxID_OK )
1674  return nullptr;
1675 
1676  switch( dlg.GetSelection() )
1677  {
1678  case 0: return &SYMBOL_LIB_TABLE::GetGlobalLibTable();
1679  case 1: return Prj().SchSymbolLibTable();
1680  default: return nullptr;
1681  }
1682 }
1683 
1684 
1685 bool LIB_EDIT_FRAME::backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt )
1686 {
1687  if( aOriginalFile.FileExists() )
1688  {
1689  wxFileName backupFileName( aOriginalFile );
1690  backupFileName.SetExt( "bck" );
1691 
1692  if( backupFileName.FileExists() )
1693  wxRemoveFile( backupFileName.GetFullPath() );
1694 
1695  if( !wxCopyFile( aOriginalFile.GetFullPath(), backupFileName.GetFullPath() ) )
1696  {
1697  DisplayError( this, _( "Failed to save backup document to file " ) +
1698  backupFileName.GetFullPath() );
1699  return false;
1700  }
1701  }
1702 
1703  return true;
1704 }
1705 
1706 
1708 {
1709  if( m_my_part && !GetCurLib().IsEmpty() && GetScreen()->IsModify() )
1710  m_libMgr->UpdatePart( m_my_part, GetCurLib() ); // UpdatePart() makes a copy
1711 }
1712 
1713 
1714 bool LIB_EDIT_FRAME::isCurrentPart( const LIB_ID& aLibId ) const
1715 {
1716  // This will return the root part of any alias
1717  LIB_PART* part = m_libMgr->GetBufferedPart( aLibId.GetLibItemName(), aLibId.GetLibNickname() );
1718  // Now we can compare the libId of the current part and the root part
1719  return ( part && GetCurPart() && part->GetLibId() == GetCurPart()->GetLibId() );
1720 }
1721 
1722 
1724 {
1725  SetCurLib( wxEmptyString );
1726  SetCurPart( nullptr );
1727  m_lastDrawItem = nullptr;
1728  SetDrawItem( NULL );
1731  Zoom_Automatique( false );
1732  Refresh();
1733 }
1734 
1735 
1737 {
1739 
1740  ReCreateHToolbar();
1741  ReCreateVToolbar();
1743  Layout();
1744  SendSizeEvent();
1745 }
1746 
1747 
1749 {
1750  // call my base class
1752 
1753  // tooltips in toolbars
1754  ReCreateHToolbar();
1755  ReCreateVToolbar();
1757 
1758  // status bar
1759  UpdateMsgPanel();
1760 }
1761 
1762 
1764 {
1765  EDA_DRAW_FRAME::SetScreen( aScreen );
1766 }
1767 
1768 
1770 {
1774 
1777 
1778  GetCanvas()->Refresh();
1779 }
1780 
1781 
1783 {
1784  RebuildView();
1785 }
1786 
1787 
1789 {
1790  LIB_PART* part = GetCurPart();
1791 
1792  if( !part )
1793  {
1794  return BOX2I( VECTOR2I(-100, -100), VECTOR2I( 200, 200 ) );
1795  }
1796  else
1797  {
1800  }
1801 }
1802 
1803 
1805 {
1806  const std::string& payload = mail.GetPayload();
1807 
1808  switch( mail.Command() )
1809  {
1810  case MAIL_LIB_EDIT:
1811  if( !payload.empty() )
1812  {
1813  wxString libFileName( payload );
1814  wxString libNickname;
1815  wxString msg;
1816 
1817  SYMBOL_LIB_TABLE* libTable = Prj().SchSymbolLibTable();
1818  const LIB_TABLE_ROW* libTableRow = libTable->FindRowByURI( libFileName );
1819 
1820  if( !libTableRow )
1821  {
1822  msg.Printf( _( "The current configuration does not include the symbol library\n"
1823  "\"%s\".\nUse Manage Symbol Libraries to edit the configuration." ),
1824  libFileName );
1825  DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
1826  break;
1827  }
1828 
1829  libNickname = libTableRow->GetNickName();
1830 
1831  if( !libTable->HasLibrary( libNickname, true ) )
1832  {
1833  msg.Printf( _( "The library with the nickname \"%s\" is not enabled\n"
1834  "in the current configuration. Use Manage Symbol Libraries to\n"
1835  "edit the configuration." ), libNickname );
1836  DisplayErrorMessage( this, _( "Symbol library not enabled." ), msg );
1837  break;
1838  }
1839 
1840  SetCurLib( libNickname );
1841 
1842  if( m_treePane )
1843  {
1844  LIB_ID id( libNickname, wxEmptyString );
1845  m_treePane->GetLibTree()->ExpandLibId( id );
1846  m_treePane->GetLibTree()->CenterLibId( id );
1847  }
1848  }
1849 
1850  break;
1851 
1852  default:
1853  ;
1854  }
1855 }
1856 
1857 
1858 void LIB_EDIT_FRAME::OnSwitchCanvas( wxCommandEvent& aEvent )
1859 {
1860  // switches currently used canvas ( Cairo / OpenGL):
1862 
1863  // Set options specific to symbol editor (axies are always enabled):
1864  GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
1865 }
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
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.
LIB_PART * GetCurPart() const
Return the current part being edited or NULL if none selected.
void OnToggleSearchTree(wxCommandEvent &event)
void OnCheckComponent(wxCommandEvent &event)
Definition: pinedit.cpp:590
void OnSaveAll(wxCommandEvent &aEvent)
Saves all modified parts and libraries.
Definition: libedit.cpp:269
int GetUnitCount() const
void OnUpdateEditingPart(wxUpdateUIEvent &event)
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
void OnUpdatePartNumber(wxUpdateUIEvent &event)
#define DEFAULTPINLENGTH
The default pin number size when creating pins(can be changed in preference menu)
Definition: general.h:62
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
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.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
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
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
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
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
int GetSelected() const
Function GetSelected() Returns the position of selected item.
Definition: context_menu.h:124
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
#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)
void OnOpenLibraryViewer(wxCommandEvent &event)
Open the library viewer only to browse library contents.
static int m_convert
void OnExportPart(wxCommandEvent &event)
Creates a new library and backup the current component in this library or exports the component of th...
Definition: lib_export.cpp:101
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:257
void RestoreComponent()
Restore the current edited component from its temporary copy.
LIB_ALIAS * GetAlias(size_t aIndex)
void OnCreateNewPart(wxCommandEvent &aEvent)
Creates a new part in the selected library.
Definition: libedit.cpp:277
This file is part of the common library.
Define a symbol library graphical text item.
Definition: lib_text.h:44
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
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)
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 OnEditPin(wxCommandEvent &event)
Definition: pinedit.cpp:94
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.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:935
Field object used in symbol libraries.
Definition: lib_field.h:59
virtual void OnActivate(wxActivateEvent &event) override
Called when the frame is activated.
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
void OnImportPart(wxCommandEvent &event)
Routine to read one part.
Definition: lib_export.cpp:39
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:1443
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
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.
void OnUpdateRedo(wxUpdateUIEvent &event)
void Process_Config(wxCommandEvent &event)
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.
bool IsMenuActive() const
Returns the status of right-click context menu.
Definition: lib_tree.h:106
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
bool isCurrentPart(const LIB_ID &aLibId) const
Returns true if aLibId is an alias for the editor screen part.
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...
virtual void SetAutoPanRequest(bool aEnable)=0
LIB_ITEM * GetCurLibItem() const
Definition: sch_screen.h:197
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
The base class for create windows for drawing purpose.
Definition: draw_frame.h:81
virtual void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
void OnUpdateSave(wxUpdateUIEvent &aEvent)
bool IsValid() const
Definition: lib_id.h:171
void OnUpdatePaste(wxUpdateUIEvent &event)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
void CloseWindow(wxCommandEvent &event)
Trigger the wxCloseEvent, which is handled by the function given to EVT_CLOSE() macro:
void StartMoveDrawSymbol(wxDC *DC, LIB_ITEM *aItem)
Definition: symbdraw.cpp:269
void OnUpdateDeMorganConvert(wxUpdateUIEvent &event)
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...
void OnUpdateRevert(wxUpdateUIEvent &aEvent)
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.
void OnAddLibrary(wxCommandEvent &aEvent)
Adds an existing library.
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.
const wxString & GetDocFileName() const
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
Pcbnew hotkeys.
void GetKicadHelp(wxCommandEvent &event)
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
void OnOrient(wxCommandEvent &aEvent)
Handles the ID_LIBEDIT_MIRROR_X and ID_LIBEDIT_MIRROR_Y events.
void OnPreferencesOptions(wxCommandEvent &event)
void StartModifyDrawSymbol(wxDC *DC, LIB_ITEM *aItem)
Definition: symbdraw.cpp:292
void OnEditComponentProperties(wxCommandEvent &event)
void OnSave(wxCommandEvent &aEvent)
Saves the selected part or library.
Definition: libedit.cpp:364
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:59
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
const wxString & GetNickName() const
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
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)
wxString GetUniqueLibraryName() const
Returns a library name that is not currently in use.
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.
void OnPasteDuplicatePart(wxCommandEvent &aEvent)
Definition: libedit.cpp:536
bool InEditMode() const
Return the draw item editing mode status.
const std::string SchematicLibraryFileExtension
virtual void CrossHairOn(wxDC *DC=nullptr)
bool IsPartModified(const wxString &aAlias, const wxString &aLibrary) const
Returns true if part has unsaved modifications.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
int ShowQuasiModal()
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
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
coord_type GetWidth() const
Definition: box2.h:195
SCH_DRAW_PANEL * GetCanvas() const override
wxComboBox * m_partSelectBox
a Box to select a part to edit (if any)
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:147
const LIB_ID & GetLibId() const
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.
void OnRemovePart(wxCommandEvent &aEvent)
Removes a part from the working copy of a library.
Definition: libedit.cpp:499
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.
void GetKicadAbout(wxCommandEvent &event)
void GetComponentFromRedoList(wxCommandEvent &event)
Definition of file extensions used in Kicad.
void OnPlotCurrentComponent(wxCommandEvent &event)
Plot the current symbol in SVG or PNG format.
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:177
unsigned STATUS_FLAGS
Definition: base_struct.h:147
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false)
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
bool saveSymbolLibTables(bool aGlobal, bool aProject)
Saves Symbol Library Tables to disk.
virtual void CrossHairOff(wxDC *DC=nullptr)
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
virtual void OnSize(wxSizeEvent &event)
Recalculate the size of toolbars and display panel when the frame size changes.
#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
LIB_PART * GetPart() const
Get the shared LIB_PART.
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
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'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:1539
void SetAxesEnabled(bool aAxesEnabled)
Enables drawing the axes.
int GetConvert() const
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:160
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
void Process_Special_Functions(wxCommandEvent &event)
Definition: solve.cpp:178
void SetAbortRequest(bool aAbortRequest)
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.
KIGFX::SCH_VIEW * GetView() const
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:803
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
void OnUpdateSaveAs(wxUpdateUIEvent &aEvent)
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:463
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.
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:182
void deleteItem(wxDC *aDC, LIB_ITEM *aItem)
Deletes the currently selected draw item.
void OnSaveAs(wxCommandEvent &aEvent)
Saves the selected part or library to a new name and/or location.
Definition: libedit.cpp:386
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Return the nearest aGridSize location to aPosition.
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:126
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)
#define GR_DEFAULT_DRAWMODE
Definition: general.h:73
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.
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
Vec Centre() const
Definition: box2.h:77
bool saveAllLibraries(bool aRequireConfirmation)
Definition: libedit.cpp:759
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void OnRevert(wxCommandEvent &aEvent)
Reverts unsaved changes in a part, restoring to the last saved state.
Definition: libedit.cpp:592
void OnEditPart(wxCommandEvent &aEvent)
Opens the selected part for editing.
Definition: libedit.cpp:356
void OnCopyCutPart(wxCommandEvent &aEvent)
Definition: libedit.cpp:520
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 GetKicadContribute(wxCommandEvent &event)
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
const wxString & GetName() const
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
void OnCreateNewLibrary(wxCommandEvent &aEvent)
Creates a new library.
virtual void HandleBlockPlace(wxDC *DC) override
Handles the block place command.
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
void SetIgnoreMouseEvents(bool aIgnore)
const EDA_RECT GetUnitBoundingBox(int aUnit, int aConvert) const
Get the bounding box for the symbol.
void SetOrigin(const Vec &pos)
Definition: box2.h:208
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
static wxString SubReference(int aUnit, bool aAddSeparator=true)
LIB_ID getTargetLibId() const
Returns either the part selected in the component tree, if context menu is active or the currently mo...
LIB_ITEM * GetDrawItem() const
void RemoveDrawItem(LIB_ITEM *aItem, EDA_DRAW_PANEL *aPanel=NULL, wxDC *aDc=NULL)
Remove draw aItem from list.
void EditGraphicSymbol(wxDC *DC, LIB_ITEM *DrawItem)
Definition: symbdraw.cpp:54
coord_type GetHeight() const
Definition: box2.h:196
bool IsMulti() const
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
#define DEFAULTPINNAMESIZE
The default library pane width.
Definition: general.h:68
LIB_PART * getTargetPart() const
Returns currently edited part.
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:54
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
unsigned GetCount() const
bool IsLibraryModified(const wxString &aLibrary) const
Returns true if library has unsaved modifications.
void OnGridSettings(wxCommandEvent &aEvent) override
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.
SCH_SCREEN * m_dummyScreen
Helper screen used when no part is loaded
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.
size_t GetAliasCount() const
SYMBOL_LIB_TABLE * selectSymLibTable(bool aOptional=false)
Displays a dialog asking the user to select a symbol library table.
void OnSwitchCanvas(wxCommandEvent &aEvent) override
switches currently used canvas ( Cairo / OpenGL).
Definition for part library class.
const Vec & GetOrigin() const
Definition: box2.h:191
#define DEFAULTPINNUMSIZE
The default pin name size when creating pins(can be changed in preference menu)
Definition: general.h:65
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
LIB_TREE * GetLibTree() const
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.
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:258
void OnSelectPart(wxCommandEvent &event)
EDA_UNITS_T m_UserUnits
Definition: draw_frame.h:123
LIB_TREE_MODEL_ADAPTER::PTR & GetAdapter()
Returns the adapter object that provides the stored data.
Definition: lib_manager.h:235
void GetComponentFromUndoList(wxCommandEvent &event)
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:243
virtual void ShowChangedLanguage()
Function ShowChangedLanguage redraws the menus and what not in current language.
void UpdatePartSelectList()
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...
void ClearMsgPanel(void)
Clear all messages from the message panel.
bool IsLibraryReadOnly(const wxString &aLibrary) const
Returns true if the library is stored in a read-only file.
bool UnitsLocked() const
Check whether part units are interchangeable.
void Regenerate()
Updates the component tree
virtual void OnSwitchCanvas(wxCommandEvent &aEvent)
switches currently used canvas ( Cairo / OpenGL).
void OnUpdateSearchTreeTool(wxUpdateUIEvent &aEvent)
int GetToolId() const
Definition: draw_frame.h:526
bool GetShowElectricalType()
wxString getTargetLib() const
Returns either the library selected in the component tree, if context menu is active or the library t...
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:171
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:165
virtual void UpdateMsgPanel()
Redraw the message panel.
void StartMovePin(LIB_ITEM *aPin)
Prepare the displacement of a pin.
Definition: pinedit.cpp:278
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
LIB_ALIASES GetAliases() const