KiCad PCB EDA Suite
libeditframe.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 <class_drawpanel.h>
35 #include <class_base_screen.h>
36 #include <confirm.h>
37 #include <eda_doc.h>
38 #include <gr_basic.h>
39 #include <schframe.h>
40 #include <msgpanel.h>
41 #include <confirm.h>
42 
43 #include <general.h>
44 #include <eeschema_id.h>
45 #include <libeditframe.h>
46 #include <class_library.h>
47 #include <lib_polyline.h>
48 #include <lib_pin.h>
49 
50 #include <lib_manager.h>
51 #include <widgets/cmp_tree_pane.h>
52 #include <widgets/component_tree.h>
53 #include <symbol_lib_table.h>
54 
55 #include <kicad_device_context.h>
56 #include <hotkeys.h>
57 #include <eeschema_config.h>
58 
62 
64 
65 #include <menus_helpers.h>
66 #include <wx/progdlg.h>
67 
68 
73 
75 wxSize LIB_EDIT_FRAME:: m_clientSize = wxSize( -1, -1 );
79 
80 // these values are overridden when reading the config
84 
86 
87 
88 BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
89  EVT_CLOSE( LIB_EDIT_FRAME::OnCloseWindow )
90  EVT_SIZE( LIB_EDIT_FRAME::OnSize )
91  EVT_ACTIVATE( LIB_EDIT_FRAME::OnActivate )
92 
93  // Library actions
94  EVT_TOOL( ID_LIBEDIT_NEW_LIBRARY, LIB_EDIT_FRAME::OnCreateNewLibrary )
98  EVT_MENU( ID_LIBEDIT_SAVE_ALL_LIBS, LIB_EDIT_FRAME::OnSaveAllLibraries )
100 
101  // Part actions
102  EVT_TOOL( ID_LIBEDIT_NEW_PART, LIB_EDIT_FRAME::OnCreateNewPart )
109  EVT_TOOL( ID_LIBEDIT_CUT_PART, LIB_EDIT_FRAME::OnCopyCutPart )
110  EVT_TOOL( ID_LIBEDIT_COPY_PART, LIB_EDIT_FRAME::OnCopyCutPart )
111  EVT_TOOL( ID_LIBEDIT_PASTE_PART, LIB_EDIT_FRAME::OnPasteDuplicatePart )
112  EVT_TOOL( ID_LIBEDIT_DUPLICATE_PART, LIB_EDIT_FRAME::OnPasteDuplicatePart )
113 
114  // Main horizontal toolbar.
115  EVT_TOOL( ID_TO_LIBVIEW, LIB_EDIT_FRAME::OnOpenLibraryViewer )
116  EVT_TOOL( wxID_COPY, LIB_EDIT_FRAME::Process_Special_Functions )
117  EVT_TOOL( wxID_PASTE, LIB_EDIT_FRAME::Process_Special_Functions )
118  EVT_TOOL( wxID_CUT, LIB_EDIT_FRAME::Process_Special_Functions )
119  EVT_TOOL( wxID_UNDO, LIB_EDIT_FRAME::GetComponentFromUndoList )
120  EVT_TOOL( wxID_REDO, LIB_EDIT_FRAME::GetComponentFromRedoList )
121  EVT_TOOL( ID_LIBEDIT_GET_FRAME_EDIT_PART, LIB_EDIT_FRAME::OnEditComponentProperties )
122  EVT_TOOL( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, LIB_EDIT_FRAME::InstallFieldsEditorDialog )
123  EVT_TOOL( ID_LIBEDIT_CHECK_PART, LIB_EDIT_FRAME::OnCheckComponent )
124  EVT_TOOL( ID_DE_MORGAN_NORMAL_BUTT, LIB_EDIT_FRAME::OnSelectBodyStyle )
125  EVT_TOOL( ID_DE_MORGAN_CONVERT_BUTT, LIB_EDIT_FRAME::OnSelectBodyStyle )
126  EVT_TOOL( ID_LIBEDIT_VIEW_DOC, LIB_EDIT_FRAME::OnViewEntryDoc )
127  EVT_TOOL( ID_LIBEDIT_EDIT_PIN_BY_PIN, LIB_EDIT_FRAME::Process_Special_Functions )
129 
132 
133  // Right vertical toolbar.
135  EVT_TOOL( ID_ZOOM_SELECTION, LIB_EDIT_FRAME::OnSelectTool )
137  LIB_EDIT_FRAME::OnSelectTool )
138 
139  // Left vertical toolbar (option toolbar).
142 
143  // menubar commands
144  EVT_MENU( wxID_EXIT, LIB_EDIT_FRAME::CloseWindow )
145  EVT_MENU( ID_LIBEDIT_GEN_PNG_FILE, LIB_EDIT_FRAME::OnPlotCurrentComponent )
146  EVT_MENU( ID_LIBEDIT_GEN_SVG_FILE, LIB_EDIT_FRAME::OnPlotCurrentComponent )
147  EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
148  EVT_MENU( wxID_INDEX, EDA_DRAW_FRAME::GetKicadHelp )
149  EVT_MENU( ID_HELP_GET_INVOLVED, EDA_DRAW_FRAME::GetKicadContribute )
150  EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout )
151 
152  EVT_MENU( wxID_PREFERENCES, LIB_EDIT_FRAME::OnPreferencesOptions )
153 
154  // Multiple item selection context menu commands.
156 
158  LIB_EDIT_FRAME::Process_Config )
159 
160  // Context menu events and commands.
163 
166  LIB_EDIT_FRAME::Process_Special_Functions )
167 
169  LIB_EDIT_FRAME::Process_Special_Functions )
170 
172  LIB_EDIT_FRAME::OnOrient )
173 
174  // Update user interface elements.
175  EVT_UPDATE_UI( wxID_PASTE, LIB_EDIT_FRAME::OnUpdatePaste )
176  EVT_UPDATE_UI( ID_LIBEDIT_REVERT_LIBRARY, LIB_EDIT_FRAME::OnUpdateLibModified )
177  EVT_UPDATE_UI( ID_LIBEDIT_EXPORT_PART, LIB_EDIT_FRAME::OnUpdateEditingPart )
178  EVT_UPDATE_UI( ID_LIBEDIT_SAVE_PART, LIB_EDIT_FRAME::OnUpdatePartModified )
179  EVT_UPDATE_UI( ID_LIBEDIT_REVERT_PART, LIB_EDIT_FRAME::OnUpdatePartModified )
180  EVT_UPDATE_UI( ID_LIBEDIT_PASTE_PART, LIB_EDIT_FRAME::OnUpdateClipboardNotEmpty )
181  EVT_UPDATE_UI( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, LIB_EDIT_FRAME::OnUpdateEditingPart )
182  EVT_UPDATE_UI( ID_LIBEDIT_CHECK_PART, LIB_EDIT_FRAME::OnUpdateEditingPart )
183  EVT_UPDATE_UI( ID_LIBEDIT_GET_FRAME_EDIT_PART, LIB_EDIT_FRAME::OnUpdateEditingPart )
184  EVT_UPDATE_UI( wxID_UNDO, LIB_EDIT_FRAME::OnUpdateUndo )
185  EVT_UPDATE_UI( wxID_REDO, LIB_EDIT_FRAME::OnUpdateRedo )
186  EVT_UPDATE_UI( ID_LIBEDIT_SAVE_LIBRARY, LIB_EDIT_FRAME::OnUpdateSaveLib )
187  EVT_UPDATE_UI( ID_LIBEDIT_SAVE_LIBRARY_AS, LIB_EDIT_FRAME::OnUpdateSaveLibAs )
188  EVT_UPDATE_UI( ID_LIBEDIT_VIEW_DOC, LIB_EDIT_FRAME::OnUpdateViewDoc )
189  EVT_UPDATE_UI( ID_LIBEDIT_EDIT_PIN_BY_PIN, LIB_EDIT_FRAME::OnUpdatePinByPin )
190  EVT_UPDATE_UI( ID_LIBEDIT_EDIT_PIN_BY_TABLE, LIB_EDIT_FRAME::OnUpdatePinTable )
191  EVT_UPDATE_UI( ID_LIBEDIT_SELECT_PART_NUMBER, LIB_EDIT_FRAME::OnUpdatePartNumber )
192  EVT_UPDATE_UI( ID_LIBEDIT_SELECT_ALIAS, LIB_EDIT_FRAME::OnUpdateSelectAlias )
193  EVT_UPDATE_UI( ID_DE_MORGAN_NORMAL_BUTT, LIB_EDIT_FRAME::OnUpdateDeMorganNormal )
194  EVT_UPDATE_UI( ID_DE_MORGAN_CONVERT_BUTT, LIB_EDIT_FRAME::OnUpdateDeMorganConvert )
195  EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, LIB_EDIT_FRAME::OnUpdateSelectTool )
196  EVT_UPDATE_UI( ID_ZOOM_SELECTION, LIB_EDIT_FRAME::OnUpdateSelectTool )
197  EVT_UPDATE_UI_RANGE( ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_DELETE_ITEM_BUTT,
198  LIB_EDIT_FRAME::OnUpdateEditingPart )
199  EVT_UPDATE_UI( ID_LIBEDIT_SHOW_ELECTRICAL_TYPE, LIB_EDIT_FRAME::OnUpdateElectricalType )
200 
201 END_EVENT_TABLE()
202 
203 #define LIB_EDIT_FRAME_NAME wxT( "LibeditFrame" )
204 
205 LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
206  SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_LIB_EDITOR, _( "Library Editor" ),
207  wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, LIB_EDIT_FRAME_NAME )
208 {
209  m_showAxis = true; // true to draw axis
210  SetShowDeMorgan( false );
211  m_drawSpecificConvert = true;
212  m_drawSpecificUnit = false;
214  m_editPinsSeparately = false;
216  SetShowElectricalType( true );
217 
218  m_my_part = NULL;
219  m_tempCopyComponent = NULL;
220  m_treePane = nullptr;
221  m_libMgr = nullptr;
222 
223  // Delayed initialization
224  if( m_textSize == -1 )
226 
227  // Initialize grid id to the default value 50 mils:
229 
230  wxIcon icon;
231  icon.CopyFromBitmap( KiBitmap( icon_libedit_xpm ) );
232  SetIcon( icon );
233 
234  LoadSettings( config() );
235 
236  m_dummyScreen = new SCH_SCREEN( aKiway );
238  GetScreen()->m_Center = true;
240 
241  SetCrossHairPosition( wxPoint( 0, 0 ) );
242 
243  // Ensure m_LastGridSizeId is an offset inside the allowed schematic range
244  if( m_LastGridSizeId < ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000 )
246 
247  if( m_LastGridSizeId > ID_POPUP_GRID_LEVEL_1 - ID_POPUP_GRID_LEVEL_1000 )
249 
250  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
251 
252  GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
253 
254  if( m_canvas )
256 
257  m_libMgr = new LIB_MANAGER( *this );
258  SyncLibraries( true );
259  m_treePane = new CMP_TREE_PANE( this, m_libMgr );
260 
261  ReCreateMenuBar();
264 
265  // Ensure the current alias name is valid if a part is loaded
266  // Sometimes it is not valid. This is the case
267  // when a part value (the part lib name), or the alias list was modified
268  // during a previous session and the modifications not saved in lib.
269  // Reopen libedit in a new session gives a non valid m_aliasName
270  // because the curr part is reloaded from the library (and this is the unmodified part)
271  // and the old alias name (from the previous edition) can be invalid
272  LIB_PART* part = GetCurPart();
273 
274  if( part == NULL )
275  m_aliasName.Empty();
276  else if( m_aliasName != part->GetName() )
277  {
278  LIB_ALIAS* alias = part->GetAlias( m_aliasName );
279 
280  if( !alias )
281  m_aliasName = part->GetName();
282  }
283 
285  DisplayLibInfos();
286  DisplayCmpDoc();
289 
290  m_auimgr.SetManagedWindow( this );
291 
292  EDA_PANEINFO horiz;
293  horiz.HorizontalToolbarPane();
294 
295  EDA_PANEINFO vert;
296  vert.VerticalToolbarPane();
297 
298  EDA_PANEINFO mesg;
299  mesg.MessageToolbarPane();
300 
301  m_auimgr.AddPane( m_mainToolBar,
302  wxAuiPaneInfo( horiz ).Name( "m_mainToolBar" ).Top().Row( 0 ) );
303 
304  m_auimgr.AddPane( m_drawToolBar,
305  wxAuiPaneInfo( vert ).Name( "m_VToolBar" ).Right() );
306 
307  m_auimgr.AddPane( m_optionsToolBar,
308  wxAuiPaneInfo( vert ).Name( "m_optionsToolBar" ).Left().Row( 0 ) );
309 
310  m_auimgr.AddPane( m_canvas,
311  wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
312 
313  m_auimgr.AddPane( m_messagePanel,
314  wxAuiPaneInfo( mesg ).Name( "MsgPanel" ).Bottom().Layer( 10 ) );
315 
316  m_auimgr.AddPane( m_treePane, wxAuiPaneInfo().Name( "ComponentTree" ).Left().Row( 1 )
317  .Resizable().MinSize( 250, 400 ).Dock().CloseButton( false ) );
318 
319  m_auimgr.Update();
320 
321  Raise();
322  Show( true );
323 
324  Bind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnEditSymbolLibTable, this,
326 
327  wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, ID_ZOOM_PAGE );
328  wxPostEvent( this, evt );
329 }
330 
331 
333 {
334  Unbind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnEditSymbolLibTable, this,
336 
337  // current screen is destroyed in EDA_DRAW_FRAME
339 
340  m_lastDrawItem = NULL;
342 
343  delete m_tempCopyComponent;
344  delete m_libMgr;
345  delete m_my_part;
346 }
347 
348 
349 void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
350 {
351  if( saveAllLibraries() )
352  {
353  saveSymbolLibTables( true, true );
354  Destroy();
355  }
356  else
357  {
358  Event.Veto();
359  }
360 }
361 
362 
364 {
365  /* Please, note: wxMSW before version 2.9 seems have
366  * problems with zoom values < 1 ( i.e. userscale > 1) and needs to be patched:
367  * edit file <wxWidgets>/src/msw/dc.cpp
368  * search for line static const int VIEWPORT_EXTENT = 1000;
369  * and replace by static const int VIEWPORT_EXTENT = 10000;
370  */
371  int dx, dy;
372 
373  LIB_PART* part = GetCurPart();
374 
375  if( part )
376  {
378 
379  dx = boundingBox.GetWidth();
380  dy = boundingBox.GetHeight();
381  SetScrollCenterPosition( wxPoint( 0, 0 ) );
382  }
383  else
384  {
385  const PAGE_INFO& pageInfo = GetScreen()->GetPageSettings();
386 
387  dx = pageInfo.GetSizeIU().x;
388  dy = pageInfo.GetSizeIU().y;
389 
390  SetScrollCenterPosition( wxPoint( 0, 0 ) );
391  }
392 
393  wxSize size = m_canvas->GetClientSize();
394 
395  // Reserve a 10% margin around component bounding box.
396  double margin_scale_factor = 0.8;
397  double zx =(double) dx / ( margin_scale_factor * (double)size.x );
398  double zy = (double) dy / ( margin_scale_factor * (double)size.y );
399 
400  double bestzoom = std::max( zx, zy );
401 
402  // keep it >= minimal existing zoom (can happen for very small components
403  // for instance when starting a new component
404  if( bestzoom < GetScreen()->m_ZoomList[0] )
405  bestzoom = GetScreen()->m_ZoomList[0];
406 
407  return bestzoom;
408 }
409 
410 
412 {
413  if( m_aliasSelectBox == NULL )
414  return;
415 
416  m_aliasSelectBox->Clear();
417 
418  LIB_PART* part = GetCurPart();
419 
420  if( !part )
421  return;
422 
423  m_aliasSelectBox->Append( part->GetAliasNames() );
424  m_aliasSelectBox->SetSelection( 0 );
425 
426  int index = m_aliasSelectBox->FindString( m_aliasName );
427 
428  if( index != wxNOT_FOUND )
429  m_aliasSelectBox->SetSelection( index );
430 }
431 
432 
434 {
435  if( m_partSelectBox == NULL )
436  return;
437 
438  if( m_partSelectBox->GetCount() != 0 )
439  m_partSelectBox->Clear();
440 
441  LIB_PART* part = GetCurPart();
442 
443  if( !part || part->GetUnitCount() <= 1 )
444  {
445  m_unit = 1;
446  m_partSelectBox->Append( wxEmptyString );
447  }
448  else
449  {
450  for( int i = 0; i < part->GetUnitCount(); i++ )
451  {
452  wxString sub = LIB_PART::SubReference( i+1, false );
453  wxString unit = wxString::Format( _( "Unit %s" ), GetChars( sub ) );
454  m_partSelectBox->Append( unit );
455  }
456  }
457 
458  // Ensure the current selected unit is compatible with
459  // the number of units of the current part:
460  if( part && part->GetUnitCount() < m_unit )
461  m_unit = 1;
462 
463  m_partSelectBox->SetSelection( ( m_unit > 0 ) ? m_unit - 1 : 0 );
464 }
465 
466 
467 void LIB_EDIT_FRAME::OnShowElectricalType( wxCommandEvent& event )
468 {
470  GetCanvas()->Refresh();
471 }
472 
473 
474 void LIB_EDIT_FRAME::OnToggleSearchTree( wxCommandEvent& event )
475 {
476  auto& treePane = m_auimgr.GetPane( m_treePane );
477  treePane.Show( !IsSearchTreeShown() );
478  m_auimgr.Update();
479 }
480 
481 
482 void LIB_EDIT_FRAME::OnEditSymbolLibTable( wxCommandEvent& aEvent )
483 {
485  SyncLibraries( true );
486 }
487 
488 
490 {
491  return m_auimgr.GetPane( m_treePane ).IsShown();
492 }
493 
494 
495 void LIB_EDIT_FRAME::OnUpdateSelectTool( wxUpdateUIEvent& aEvent )
496 {
497  aEvent.Check( GetToolId() == aEvent.GetId() );
498 }
499 
500 
501 void LIB_EDIT_FRAME::OnUpdateElectricalType( wxUpdateUIEvent& aEvent )
502 {
503  aEvent.Check( GetShowElectricalType() );
504 }
505 
506 
507 void LIB_EDIT_FRAME::OnUpdateEditingPart( wxUpdateUIEvent& aEvent )
508 {
509  LIB_PART* part = GetCurPart();
510 
511  aEvent.Enable( part != NULL );
512 
513  if( part && aEvent.GetEventObject() == m_drawToolBar )
514  aEvent.Check( GetToolId() == aEvent.GetId() );
515 }
516 
517 
518 void LIB_EDIT_FRAME::OnUpdatePartModified( wxUpdateUIEvent& aEvent )
519 {
520  LIB_ID libId = getTargetLibId();
521  const wxString& partName = libId.GetLibItemName();
522  const wxString& libName = libId.GetLibNickname();
523 
524  if( aEvent.GetId() == ID_LIBEDIT_SAVE_PART )
525  {
526  bool readOnly = libName.IsEmpty() || m_libMgr->IsLibraryReadOnly( libName );
527  wxString text = AddHotkeyName( readOnly ? _( "&Save Part [Read Only]" ) : _( "&Save Part" ),
529 
530  aEvent.SetText( text );
531  aEvent.Enable( !readOnly && !partName.IsEmpty()
532  && m_libMgr->IsPartModified( partName, libName ) );
533  }
534  else if( aEvent.GetId() == ID_LIBEDIT_REVERT_PART )
535  {
536  aEvent.Enable( !partName.IsEmpty() && !libName.IsEmpty()
537  && m_libMgr->IsPartModified( partName, libName ) );
538  }
539  else wxFAIL;
540 }
541 
542 
543 void LIB_EDIT_FRAME::OnUpdatePaste( wxUpdateUIEvent& event )
544 {
545  event.Enable( m_clipboard.GetCount() > 0 );
546 }
547 
548 
549 void LIB_EDIT_FRAME::OnUpdateLibModified( wxUpdateUIEvent& aEvent )
550 {
551  aEvent.Enable( m_libMgr->IsLibraryModified( getTargetLib() ) );
552 }
553 
554 
555 void LIB_EDIT_FRAME::OnUpdateClipboardNotEmpty( wxUpdateUIEvent& aEvent )
556 {
557  aEvent.Enable( !!m_copiedPart );
558 }
559 
560 
561 void LIB_EDIT_FRAME::OnUpdateUndo( wxUpdateUIEvent& event )
562 {
563  event.Enable( GetCurPart() && GetScreen() &&
564  GetScreen()->GetUndoCommandCount() != 0 && !IsEditingDrawItem() );
565 }
566 
567 
568 void LIB_EDIT_FRAME::OnUpdateRedo( wxUpdateUIEvent& event )
569 {
570  event.Enable( GetCurPart() && GetScreen() &&
571  GetScreen()->GetRedoCommandCount() != 0 && !IsEditingDrawItem() );
572 }
573 
574 
575 void LIB_EDIT_FRAME::OnUpdateSaveLib( wxUpdateUIEvent& event )
576 {
577  wxString lib = getTargetLib();
578  bool readOnly = lib.IsEmpty() || m_libMgr->IsLibraryReadOnly( lib );
579 
580  wxString text = AddHotkeyName( readOnly ? _( "&Save Library [Read Only]" )
581  : _( "&Save Library" ) , g_Libedit_Hokeys_Descr, HK_SAVE_PART );
582 
583  event.SetText( text );
584  event.Enable( !readOnly && m_libMgr->IsLibraryModified( lib ) );
585 }
586 
587 
588 void LIB_EDIT_FRAME::OnUpdateSaveLibAs( wxUpdateUIEvent& event )
589 {
590  wxString lib = getTargetLib();
591 
592  event.Enable( m_libMgr->LibraryExists( lib ) );
593 }
594 
595 
596 void LIB_EDIT_FRAME::OnUpdateViewDoc( wxUpdateUIEvent& event )
597 {
598  bool enable = false;
599 
600  LIB_PART* part = GetCurPart();
601 
602  if( part )
603  {
604  LIB_ALIAS* alias = part->GetAlias( m_aliasName );
605 
606  wxCHECK_RET( alias != NULL,
607  wxString::Format( "Alias \"%s\" not found in symbol \"%s\".",
608  m_aliasName, part->GetName() ) );
609 
610  enable = !alias->GetDocFileName().IsEmpty();
611  }
612 
613  event.Enable( enable );
614 }
615 
616 
617 void LIB_EDIT_FRAME::OnUpdatePinByPin( wxUpdateUIEvent& event )
618 {
619  LIB_PART* part = GetCurPart();
620 
621  event.Enable( part && part->GetUnitCount() > 1 && !part->UnitsLocked() );
622 
623  event.Check( m_editPinsSeparately );
624 }
625 
626 
627 void LIB_EDIT_FRAME::OnUpdatePinTable( wxUpdateUIEvent& event )
628 {
629  LIB_PART* part = GetCurPart();
630  event.Enable( part != NULL );
631 }
632 
633 
634 void LIB_EDIT_FRAME::OnUpdatePartNumber( wxUpdateUIEvent& event )
635 {
636  if( m_partSelectBox == NULL )
637  return;
638 
639  LIB_PART* part = GetCurPart();
640 
641  // Using the typical event.Enable() call doesn't seem to work with wxGTK
642  // so use the pointer to alias combobox to directly enable or disable.
643  m_partSelectBox->Enable( part && part->GetUnitCount() > 1 );
644 }
645 
646 
647 void LIB_EDIT_FRAME::OnUpdateDeMorganNormal( wxUpdateUIEvent& event )
648 {
649  if( m_mainToolBar == NULL )
650  return;
651 
652  LIB_PART* part = GetCurPart();
653 
654  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
655  event.Check( m_convert <= 1 );
656 }
657 
658 
659 void LIB_EDIT_FRAME::OnUpdateDeMorganConvert( wxUpdateUIEvent& event )
660 {
661  if( m_mainToolBar == NULL )
662  return;
663 
664  LIB_PART* part = GetCurPart();
665 
666  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
667  event.Check( m_convert > 1 );
668 }
669 
670 
671 void LIB_EDIT_FRAME::OnUpdateSelectAlias( wxUpdateUIEvent& event )
672 {
673  if( m_aliasSelectBox == NULL )
674  return;
675 
676  LIB_PART* part = GetCurPart();
677 
678  // Using the typical event.Enable() call doesn't seem to work with wxGTK
679  // so use the pointer to alias combobox to directly enable or disable.
680  m_aliasSelectBox->Enable( part && part->GetAliasCount() > 1 );
681 }
682 
683 
684 void LIB_EDIT_FRAME::OnSelectAlias( wxCommandEvent& event )
685 {
686  if( m_aliasSelectBox == NULL
687  || ( m_aliasSelectBox->GetStringSelection().CmpNoCase( m_aliasName ) == 0) )
688  return;
689 
690  m_lastDrawItem = NULL;
691  m_aliasName = m_aliasSelectBox->GetStringSelection();
692 
693  DisplayCmpDoc();
694  m_canvas->Refresh();
695 }
696 
697 
698 void LIB_EDIT_FRAME::OnSelectPart( wxCommandEvent& event )
699 {
700  int i = event.GetSelection();
701 
702  if( ( i == wxNOT_FOUND ) || ( ( i + 1 ) == m_unit ) )
703  return;
704 
705  m_lastDrawItem = NULL;
706  m_unit = i + 1;
707  m_canvas->Refresh();
708  DisplayCmpDoc();
709 }
710 
711 
712 void LIB_EDIT_FRAME::OnViewEntryDoc( wxCommandEvent& event )
713 {
714  LIB_PART* part = GetCurPart();
715 
716  if( !part )
717  return;
718 
719  wxString fileName;
720  LIB_ALIAS* alias = part->GetAlias( m_aliasName );
721 
722  wxCHECK_RET( alias != NULL, "Alias not found." );
723 
724  fileName = alias->GetDocFileName();
725 
726  if( !fileName.IsEmpty() )
727  {
728  SEARCH_STACK* lib_search = Prj().SchSearchS();
729 
730  GetAssociatedDocument( this, fileName, lib_search );
731  }
732 }
733 
734 
735 void LIB_EDIT_FRAME::OnSelectBodyStyle( wxCommandEvent& event )
736 {
737  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
738 
739  if( event.GetId() == ID_DE_MORGAN_NORMAL_BUTT )
740  m_convert = 1;
741  else
742  m_convert = 2;
743 
744  m_lastDrawItem = NULL;
745  m_canvas->Refresh();
746 }
747 
748 
749 void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
750 {
751  int id = event.GetId();
752  wxPoint pos;
753  SCH_SCREEN* screen = GetScreen();
755  LIB_ITEM* item = screen->GetCurLibItem();
756 
758 
759  wxGetMousePosition( &pos.x, &pos.y );
760  pos.y += 20;
761 
762  switch( id ) // Stop placement commands before handling new command.
763  {
764  case wxID_COPY:
765  case wxID_CUT:
767  case ID_LIBEDIT_EDIT_PIN:
773  case ID_POPUP_ZOOM_BLOCK:
781  case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT:
782  break;
783 
785  if( m_canvas->IsMouseCaptured() )
787  else
788  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
789  break;
790 
793  break;
794 
795  default:
796  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(),
797  wxEmptyString );
798  break;
799  }
800 
802 
803  switch( id )
804  {
806  break;
807 
808  case ID_LIBEDIT_EDIT_PIN_BY_PIN:
809  m_editPinsSeparately = m_mainToolBar->GetToolToggled( ID_LIBEDIT_EDIT_PIN_BY_PIN );
810  break;
811 
814  if( item )
815  {
816  EndDrawGraphicItem( &dc );
817  }
818  break;
819 
821  if( item )
822  {
823  m_canvas->CrossHairOff( &dc );
824 
825  switch( item->Type() )
826  {
827  case LIB_ARC_T:
828  case LIB_CIRCLE_T:
829  case LIB_RECTANGLE_T:
830  case LIB_POLYLINE_T:
831  EditGraphicSymbol( &dc, item );
832  break;
833 
834  case LIB_TEXT_T:
835  EditSymbolText( &dc, item );
836  break;
837 
838  default:
839  ;
840  }
841 
842  m_canvas->CrossHairOn( &dc );
843  }
844  break;
845 
846  case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT:
847  {
848  // Delete the last created segment, while creating a polyline draw item
849  if( item == NULL )
850  break;
851 
853  STATUS_FLAGS oldFlags = item->GetFlags();
854  item->ClearFlags();
855  item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
857  ( (LIB_POLYLINE*) item )->DeleteSegment( GetCrossHairPosition( true ) );
858  item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
860  item->SetFlags( oldFlags );
861  m_lastDrawItem = NULL;
862  }
863  break;
864 
866  if( item )
867  deleteItem( &dc );
868 
869  break;
870 
872  if( item == NULL )
873  break;
874 
875  if( item->Type() == LIB_PIN_T )
876  StartMovePin( &dc );
877  else
878  StartMoveDrawSymbol( &dc );
879  break;
880 
882 
883  if( item == NULL )
884  break;
885 
887  if( item->Type() == LIB_RECTANGLE_T
888  || item->Type() == LIB_CIRCLE_T
889  || item->Type() == LIB_POLYLINE_T
890  || item->Type() == LIB_ARC_T
891  )
892  {
893  StartModifyDrawSymbol( &dc );
894  }
895 
896  break;
897 
899  if( item == NULL )
900  break;
901 
902  m_canvas->CrossHairOff( &dc );
903 
904  if( item->Type() == LIB_FIELD_T )
905  {
906  EditField( (LIB_FIELD*) item );
907  }
908 
910  m_canvas->CrossHairOn( &dc );
911  break;
912 
916  {
917  if( !item || item->Type() != LIB_PIN_T )
918  break;
919 
920  LIB_PART* part = GetCurPart();
921 
922  SaveCopyInUndoList( part );
923 
924  GlobalSetPins( (LIB_PIN*) item, id );
926  m_canvas->Refresh();
927  }
928  break;
929 
930  case ID_POPUP_ZOOM_BLOCK:
931  m_canvas->SetAutoPanRequest( false );
932  block.SetCommand( BLOCK_ZOOM );
933  HandleBlockEnd( &dc );
934  break;
935 
937  m_canvas->SetAutoPanRequest( false );
938  block.SetCommand( BLOCK_DELETE );
940  HandleBlockEnd( &dc );
941  break;
942 
944  m_canvas->SetAutoPanRequest( false );
945  block.SetCommand( BLOCK_DUPLICATE );
947  HandleBlockEnd( &dc );
948  break;
949 
951  m_canvas->SetAutoPanRequest( false );
954  HandleBlockEnd( &dc );
955  break;
956 
958  m_canvas->SetAutoPanRequest( false );
959  block.SetCommand( BLOCK_MIRROR_Y );
961  HandleBlockPlace( &dc );
962  break;
963 
965  m_canvas->SetAutoPanRequest( false );
966  block.SetCommand( BLOCK_MIRROR_X );
968  HandleBlockPlace( &dc );
969  break;
970 
972  m_canvas->SetAutoPanRequest( false );
973  block.SetCommand( BLOCK_ROTATE );
975  HandleBlockPlace( &dc );
976  break;
977 
979  m_canvas->SetAutoPanRequest( false );
981  HandleBlockPlace( &dc );
982  break;
983 
984  case wxID_COPY:
985  block.SetCommand( BLOCK_COPY );
986  block.SetMessageBlock( this );
987  HandleBlockEnd( &dc );
988  break;
989 
990  case wxID_PASTE:
992  break;
993 
994  case wxID_CUT:
995  if( block.GetCommand() != BLOCK_MOVE )
996  break;
997 
998  block.SetCommand( BLOCK_CUT );
999  block.SetMessageBlock( this );
1000  HandleBlockEnd( &dc );
1001  break;
1002 
1003  default:
1004  DisplayError( this, "LIB_EDIT_FRAME::Process_Special_Functions error" );
1005  break;
1006  }
1007 
1008  m_canvas->SetIgnoreMouseEvents( false );
1009 
1010  if( GetToolId() == ID_NO_TOOL_SELECTED )
1011  m_lastDrawItem = NULL;
1012 }
1013 
1014 
1015 void LIB_EDIT_FRAME::OnActivate( wxActivateEvent& event )
1016 {
1017  EDA_DRAW_FRAME::OnActivate( event );
1018 }
1019 
1020 
1022 {
1023  wxString libNickname = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_LIB );
1024 
1025  if( !libNickname.empty() )
1026  {
1027  if( !Prj().SchSymbolLibTable()->HasLibrary( libNickname ) )
1028  {
1029  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
1030  libNickname = wxEmptyString;
1031  }
1032  }
1033 
1034  return libNickname;
1035 }
1036 
1037 
1038 wxString LIB_EDIT_FRAME::SetCurLib( const wxString& aLibNickname )
1039 {
1040  wxString old = GetCurLib();
1041 
1042  if( aLibNickname.empty() || !Prj().SchSymbolLibTable()->HasLibrary( aLibNickname ) )
1043  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
1044  else
1045  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, aLibNickname );
1046 
1047  m_libMgr->SetCurrentLib( aLibNickname );
1048 
1049  return old;
1050 }
1051 
1052 
1054 {
1055  wxASSERT( m_my_part != aPart );
1056 
1057  if( m_my_part != aPart )
1058  {
1059  delete m_my_part;
1060  m_my_part = aPart;
1061  }
1062 
1063  // select the current component in the tree widget
1064  if( aPart )
1065  m_treePane->GetCmpTree()->SelectLibId( aPart->GetLibId() );
1066 
1067  wxString partName = aPart ? aPart->GetName() : wxString();
1068  m_libMgr->SetCurrentPart( partName );
1069 
1070  // retain in case this wxFrame is re-opened later on the same PROJECT
1072 }
1073 
1074 
1076 {
1077  delete m_tempCopyComponent;
1078 
1079  if( LIB_PART* part = GetCurPart() )
1080  // clone it and own the clone.
1081  m_tempCopyComponent = new LIB_PART( *part );
1082  else
1083  // clear it, there was no CurPart
1084  m_tempCopyComponent = NULL;
1085 }
1086 
1087 
1089 {
1090  if( m_tempCopyComponent )
1091  {
1092  // transfer ownership to CurPart
1094  m_tempCopyComponent = NULL;
1095  }
1096 }
1097 
1098 
1100 {
1101  delete m_tempCopyComponent;
1102  m_tempCopyComponent = NULL;
1103 }
1104 
1105 
1106 void LIB_EDIT_FRAME::EditSymbolText( wxDC* DC, LIB_ITEM* DrawItem )
1107 {
1108  if ( ( DrawItem == NULL ) || ( DrawItem->Type() != LIB_TEXT_T ) )
1109  return;
1110 
1111  // Deleting old text
1112  if( DC && !DrawItem->InEditMode() )
1113  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
1114  DefaultTransform );
1115 
1116  DIALOG_LIB_EDIT_TEXT* frame = new DIALOG_LIB_EDIT_TEXT( this, (LIB_TEXT*) DrawItem );
1117  frame->ShowModal();
1118  frame->Destroy();
1119  OnModify();
1120 
1121  // Display new text
1122  if( DC && !DrawItem->InEditMode() )
1123  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, GR_DEFAULT_DRAWMODE,
1124  NULL, DefaultTransform );
1125 }
1126 
1127 
1128 void LIB_EDIT_FRAME::OnEditComponentProperties( wxCommandEvent& event )
1129 {
1130  bool partLocked = GetCurPart()->UnitsLocked();
1131  wxString oldName = GetCurPart()->GetName();
1132 
1134 
1135  if( dlg.ShowModal() == wxID_CANCEL )
1136  return;
1137 
1138  // if m_UnitSelectionLocked has changed, set some edit options or defaults
1139  // to the best value
1140  if( partLocked != GetCurPart()->UnitsLocked() )
1141  {
1142  // m_editPinsSeparately is set to the better value
1143  m_editPinsSeparately = GetCurPart()->UnitsLocked() ? true : false;
1144  // also set default edit options to the better value
1145  // Usually if units are locked, graphic items are specific to each unit
1146  // and if units are interchangeable, graphic items are common to units
1147  m_drawSpecificUnit = GetCurPart()->UnitsLocked() ? true : false;
1148  }
1149 
1150  if( oldName != GetCurPart()->GetName() )
1151  m_libMgr->RemovePart( GetCurLib(), oldName );
1152 
1154 
1157  DisplayLibInfos();
1158  DisplayCmpDoc();
1159  OnModify();
1160  m_canvas->Refresh();
1161 }
1162 
1163 
1164 void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
1165 {
1166  int id = aEvent.GetId();
1167  int lastToolID = GetToolId();
1168 
1169  if( GetToolId() == ID_NO_TOOL_SELECTED || GetToolId() == ID_ZOOM_SELECTION )
1170  m_lastDrawItem = NULL;
1171 
1172  // Stop the current command and deselect the current tool.
1173  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
1174 
1175  LIB_PART* part = GetCurPart();
1176 
1177  switch( id )
1178  {
1179  case ID_NO_TOOL_SELECTED:
1180  SetToolID( id, m_canvas->GetDefaultCursor(), wxEmptyString );
1181  break;
1182 
1183  case ID_ZOOM_SELECTION:
1184  // This tool is located on the main toolbar: switch it on or off on click on it
1185  if( lastToolID != ID_ZOOM_SELECTION )
1186  SetToolID( ID_ZOOM_SELECTION, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) );
1187  else
1189  break;
1190 
1191  case ID_LIBEDIT_PIN_BUTT:
1192  if( part )
1193  {
1194  SetToolID( id, wxCURSOR_PENCIL, _( "Add pin" ) );
1195  }
1196  else
1197  {
1198  SetToolID( id, wxCURSOR_ARROW, _( "Set pin options" ) );
1199 
1200  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
1201 
1202  cmd.SetId( ID_LIBEDIT_EDIT_PIN );
1203  GetEventHandler()->ProcessEvent( cmd );
1205  }
1206  break;
1207 
1209  SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) );
1210  break;
1211 
1213  SetToolID( id, wxCURSOR_PENCIL, _( "Add rectangle" ) );
1214  break;
1215 
1217  SetToolID( id, wxCURSOR_PENCIL, _( "Add circle" ) );
1218  break;
1219 
1221  SetToolID( id, wxCURSOR_PENCIL, _( "Add arc" ) );
1222  break;
1223 
1225  SetToolID( id, wxCURSOR_PENCIL, _( "Add line" ) );
1226  break;
1227 
1229  SetToolID( id, wxCURSOR_HAND, _( "Set anchor position" ) );
1230  break;
1231 
1233  SetToolID( id, m_canvas->GetDefaultCursor(), _( "Import" ) );
1234  LoadOneSymbol();
1236  break;
1237 
1239  SetToolID( id, m_canvas->GetDefaultCursor(), _( "Export" ) );
1240  SaveOneSymbol();
1242  break;
1243 
1244  case ID_LIBEDIT_DELETE_ITEM_BUTT:
1245  if( !part )
1246  {
1247  wxBell();
1248  break;
1249  }
1250 
1251  SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
1252  break;
1253 
1254  default:
1255  break;
1256  }
1257 
1258  m_canvas->SetIgnoreMouseEvents( false );
1259 }
1260 
1261 
1262 void LIB_EDIT_FRAME::OnRotateItem( wxCommandEvent& aEvent )
1263 {
1264  LIB_ITEM* item = GetDrawItem();
1265 
1266  if( item == NULL )
1267  return;
1268 
1269  if( !item->InEditMode() )
1270  {
1271  LIB_PART* part = GetCurPart();
1272 
1273  SaveCopyInUndoList( part );
1274  item->SetUnit( m_unit );
1275  }
1276 
1277  item->Rotate();
1278  OnModify();
1279 
1280  if( !item->InEditMode() )
1281  item->ClearFlags();
1282 
1283  m_canvas->Refresh();
1284 
1285  if( GetToolId() == ID_NO_TOOL_SELECTED )
1286  m_lastDrawItem = NULL;
1287 }
1288 
1289 
1290 void LIB_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent )
1291 {
1293  SCH_SCREEN* screen = GetScreen();
1294  // Allows block rotate operation on hot key.
1295  if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK )
1296  {
1297  if( aEvent.GetId() == ID_LIBEDIT_MIRROR_X )
1298  {
1300  screen->m_BlockLocate.SetMessageBlock( this );
1302  HandleBlockEnd( &dc );
1303  }
1304  else if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y )
1305  {
1307  screen->m_BlockLocate.SetMessageBlock( this );
1309  HandleBlockEnd( &dc );
1310  }
1311  }
1312 }
1313 
1314 
1316  const KICAD_T aFilterList[] )
1317 {
1318  wxPoint pos;
1319  LIB_PART* part = GetCurPart();
1320 
1321  if( !part )
1322  return NULL;
1323 
1324  LIB_ITEM* item = locateItem( aPosition, aFilterList );
1325 
1326  // If the user aborted the clarification context menu, don't show it again at the
1327  // grid position.
1328  if( !item && m_canvas->GetAbortRequest() )
1329  return NULL;
1330 
1331  pos = GetNearestGridPosition( aPosition );
1332 
1333  if( item == NULL && aPosition != pos )
1334  item = locateItem( pos, aFilterList );
1335 
1336  return item;
1337 }
1338 
1339 
1340 LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aFilterList[] )
1341 {
1342  LIB_PART* part = GetCurPart();
1343 
1344  if( !part )
1345  return NULL;
1346 
1347  LIB_ITEM* item = NULL;
1348 
1349  m_collectedItems.Collect( part->GetDrawItems(), aFilterList, aPosition,
1350  m_unit, m_convert );
1351 
1352  if( m_collectedItems.GetCount() == 0 )
1353  {
1354  ClearMsgPanel();
1355  }
1356  else if( m_collectedItems.GetCount() == 1 )
1357  {
1358  item = m_collectedItems[0];
1359  }
1360  else
1361  {
1362  if( item == NULL )
1363  {
1364  wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS,
1365  "Select item clarification context menu size limit exceeded." );
1366 
1367  wxMenu selectMenu;
1368  AddMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ),
1369  KiBitmap( info_xpm ) );
1370 
1371  selectMenu.AppendSeparator();
1372 
1373  for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ )
1374  {
1375  wxString text = m_collectedItems[i]->GetSelectMenuText();
1376  BITMAP_DEF xpm = m_collectedItems[i]->GetMenuImage();
1377 
1378  AddMenuItem( &selectMenu, ID_SELECT_ITEM_START + i, text, KiBitmap( xpm ) );
1379  }
1380 
1381  // Set to NULL in case user aborts the clarification context menu.
1382  SetDrawItem( NULL );
1383  m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected
1384  PopupMenu( &selectMenu );
1386  item = GetDrawItem();
1387  }
1388  }
1389 
1390  if( item )
1391  {
1392  MSG_PANEL_ITEMS items;
1393  item->GetMsgPanelInfo( items );
1394  SetMsgPanel( items );
1395  }
1396  else
1397  {
1398  ClearMsgPanel();
1399  }
1400 
1401  return item;
1402 }
1403 
1404 
1406 {
1407  LIB_ITEM* item = GetDrawItem();
1408 
1409  wxCHECK_RET( item != NULL, "No drawing item selected to delete." );
1410 
1411  m_canvas->CrossHairOff( aDC );
1412 
1413  LIB_PART* part = GetCurPart();
1414 
1415  SaveCopyInUndoList( part );
1416 
1417  if( item->Type() == LIB_PIN_T )
1418  {
1419  LIB_PIN* pin = static_cast<LIB_PIN*>( item );
1420  wxPoint pos = pin->GetPosition();
1421 
1422  part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC );
1423 
1424  // when pin edition is synchronized, all pins of the same body style
1425  // are removed:
1426  if( SynchronizePins() )
1427  {
1428  int curr_convert = pin->GetConvert();
1429  LIB_PIN* next_pin = part->GetNextPin();
1430 
1431  while( next_pin != NULL )
1432  {
1433  pin = next_pin;
1434  next_pin = part->GetNextPin( pin );
1435 
1436  if( pin->GetPosition() != pos )
1437  continue;
1438 
1439  if( pin->GetConvert() != curr_convert )
1440  continue;
1441 
1442  part->RemoveDrawItem( pin );
1443  }
1444  }
1445 
1446  m_canvas->Refresh();
1447  }
1448  else
1449  {
1450  if( m_canvas->IsMouseCaptured() )
1451  {
1452  m_canvas->CallEndMouseCapture( aDC );
1453  }
1454  else
1455  {
1456  part->RemoveDrawItem( item, m_canvas, aDC );
1457  m_canvas->Refresh();
1458  }
1459  }
1460 
1461  SetDrawItem( NULL );
1462  m_lastDrawItem = NULL;
1463  OnModify();
1464  m_canvas->CrossHairOn( aDC );
1465 }
1466 
1467 
1469 {
1470  GetScreen()->SetModify();
1471  storeCurrentPart();
1472  m_treePane->GetCmpTree()->Refresh();
1473 }
1474 
1475 
1476 void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent )
1477 {
1478  int id = aEvent.GetId();
1479  int index = id - ID_SELECT_ITEM_START;
1480 
1481  if( (id >= ID_SELECT_ITEM_START && id <= ID_SELECT_ITEM_END)
1482  && (index >= 0 && index < m_collectedItems.GetCount()) )
1483  {
1484  LIB_ITEM* item = m_collectedItems[index];
1485  m_canvas->SetAbortRequest( false );
1486  SetDrawItem( item );
1487  }
1488 }
1489 
1490 
1491 void LIB_EDIT_FRAME::OnOpenPinTable( wxCommandEvent& aEvent )
1492 {
1493  LIB_PART* part = GetCurPart();
1494 
1495  DIALOG_LIB_EDIT_PIN_TABLE dlg( this, *part );
1496 
1497  if( dlg.ShowModal() == wxID_CANCEL )
1498  return;
1499 
1500  return;
1501 }
1502 
1503 
1505 {
1506  LIB_PART* part = GetCurPart();
1507 
1508  return !m_editPinsSeparately && part && part->IsMulti() && !part->UnitsLocked();
1509 }
1510 
1511 
1513 {
1514  // This is not the most effecient way to do this because the changed library may not have
1515  // any effect on the schematic symbol links. Since this is not called very often, take the
1516  // hit here rather than the myriad other places (including SCH_SCREEN::Draw()) where it was
1517  // being called.
1518  SCH_SCREENS schematic;
1519 
1520  schematic.UpdateSymbolLinks();
1521  schematic.TestDanglingEnds();
1522 
1523  // There may be no parent window so use KIWAY message to refresh the schematic editor
1524  // in case any symbols have changed.
1525  Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_REFRESH, std::string( "" ), this );
1526 }
1527 
1528 
1529 bool LIB_EDIT_FRAME::addLibraryFile( bool aCreateNew )
1530 {
1531  wxFileName fileName = getLibraryFileName( !aCreateNew );
1532  wxString libName = fileName.GetName();
1533  bool res = false;
1534 
1535  if( libName.IsEmpty() )
1536  return false;
1537 
1538  if( m_libMgr->LibraryExists( libName ) )
1539  {
1540  DisplayError( this,
1541  wxString::Format( _( "Library \"%s\" already exists" ), GetChars( libName ) ) );
1542  return false;
1543  }
1544 
1545  // Select the target library table (global/project)
1546  SYMBOL_LIB_TABLE* libTable = selectSymLibTable();
1547 
1548  if( !libTable )
1549  return false;
1550 
1551  if( aCreateNew )
1552  {
1553  res = m_libMgr->CreateLibrary( fileName.GetFullPath(), libTable );
1554 
1555  if( !res )
1556  DisplayError( this, _( "Could not create the library file. Check write permission." ) );
1557  }
1558  else
1559  {
1560  res = m_libMgr->AddLibrary( fileName.GetFullPath(), libTable );
1561 
1562  if( !res )
1563  DisplayError( this, _( "Could not open the library file." ) );
1564  }
1565 
1566  return res;
1567 }
1568 
1569 
1570 wxFileName LIB_EDIT_FRAME::getLibraryFileName( bool aExisting )
1571 {
1572  wxFileName fn = m_libMgr->GetUniqueLibraryName();
1573  fn.SetExt( SchematicLibraryFileExtension );
1574 
1575  wxFileDialog dlg( this,
1576  aExisting ? _( "Select Library" ) : _( "New Library" ),
1577  Prj().GetProjectPath(),
1578  aExisting ? wxString( wxEmptyString ) : fn.GetFullName() ,
1580  aExisting ? wxFD_OPEN | wxFD_FILE_MUST_EXIST :
1581  wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1582 
1583  if( dlg.ShowModal() == wxID_CANCEL )
1584  return wxFileName();
1585 
1586  fn = dlg.GetPath();
1587  fn.SetExt( SchematicLibraryFileExtension );
1588 
1589  return fn;
1590 }
1591 
1592 
1594 {
1595  LIB_ALIAS* alias = nullptr;
1596 
1597  if( m_treePane->GetCmpTree()->IsMenuActive() )
1598  {
1600  alias = m_libMgr->GetAlias( libId.GetLibItemName(), libId.GetLibNickname() );
1601  }
1602  else if( LIB_PART* part = GetCurPart() )
1603  {
1604  alias = part->GetAlias( 0 );
1605  }
1606 
1607  return alias ? alias->GetPart() : nullptr;
1608 }
1609 
1610 
1612 {
1613  if( m_treePane->GetCmpTree()->IsMenuActive() )
1614  return m_treePane->GetCmpTree()->GetSelectedLibId();
1615 
1616  if( LIB_PART* part = GetCurPart() )
1617  return part->GetLibId();
1618 
1619  return LIB_ID();
1620 }
1621 
1622 
1624 {
1625  if( m_treePane->GetCmpTree()->IsMenuActive() )
1626  {
1628  return libId.GetLibNickname();
1629  }
1630  else
1631  {
1632  return GetCurLib();
1633  }
1634 }
1635 
1636 
1637 void LIB_EDIT_FRAME::SyncLibraries( bool aProgress )
1638 {
1639  LIB_ID selected;
1640 
1641  if( m_treePane )
1642  selected = m_treePane->GetCmpTree()->GetSelectedLibId();
1643 
1644  if( aProgress )
1645  {
1646  wxProgressDialog progressDlg( _( "Loading Symbol Libraries" ),
1647  wxEmptyString, m_libMgr->GetAdapter()->GetLibrariesCount(), this );
1648 
1649  m_libMgr->Sync( true, [&]( int progress, int max, const wxString& libName ) {
1650  progressDlg.Update( progress, wxString::Format( _( "Loading library \"%s\"" ), libName ) );
1651  } );
1652  }
1653  else
1654  {
1655  m_libMgr->Sync( true );
1656  }
1657 
1658  if( m_treePane )
1659  {
1660  wxDataViewItem found;
1661 
1662  if( selected.IsValid() )
1663  {
1664  // Check if the previously selected item is still valid,
1665  // if not - it has to be unselected to prevent crash
1666  found = m_libMgr->GetAdapter()->FindItem( selected );
1667 
1668  if( !found )
1670  }
1671 
1673 
1674  // Try to select the parent library, in case the part is not found
1675  if( !found && selected.IsValid() )
1676  {
1677  selected.SetLibItemName( "" );
1678  found = m_libMgr->GetAdapter()->FindItem( selected );
1679 
1680  if( found )
1681  m_treePane->GetCmpTree()->SelectLibId( selected );
1682  }
1683  }
1684 }
1685 
1686 
1688 {
1689  wxArrayString libTableNames;
1690  libTableNames.Add( _( "Global" ) );
1691  libTableNames.Add( _( "Project" ) );
1692 
1693  switch( SelectSingleOption( this, _( "Select Symbol Library Table" ),
1694  _( "Choose the Library Table to add the library:" ), libTableNames ) )
1695  {
1696  case 0: return &SYMBOL_LIB_TABLE::GetGlobalLibTable();
1697  case 1: return Prj().SchSymbolLibTable();
1698  }
1699 
1700  return nullptr;
1701 }
1702 
1703 
1704 bool LIB_EDIT_FRAME::backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt )
1705 {
1706  if( aOriginalFile.FileExists() )
1707  {
1708  wxFileName backupFileName( aOriginalFile );
1709  backupFileName.SetExt( "bck" );
1710 
1711  if( backupFileName.FileExists() )
1712  wxRemoveFile( backupFileName.GetFullPath() );
1713 
1714  if( !wxCopyFile( aOriginalFile.GetFullPath(), backupFileName.GetFullPath() ) )
1715  {
1716  DisplayError( this, _( "Failed to save backup document to file " ) +
1717  backupFileName.GetFullPath() );
1718  return false;
1719  }
1720  }
1721 
1722  return true;
1723 }
1724 
1725 
1727 {
1728  if( m_my_part && !GetCurLib().IsEmpty() && GetScreen()->IsModify() )
1729  m_libMgr->UpdatePart( m_my_part, GetCurLib() ); // UpdatePart() makes a copy
1730 }
1731 
1732 
1733 bool LIB_EDIT_FRAME::isCurrentPart( const LIB_ID& aLibId ) const
1734 {
1735  return ( GetCurPart() && aLibId == GetCurPart()->GetLibId() );
1736 }
1737 
1738 
1740 {
1741  SetCurLib( wxEmptyString );
1742  SetCurPart( nullptr );
1743  m_aliasName.Empty();
1744  m_lastDrawItem = nullptr;
1745  SetDrawItem( NULL );
1748  Zoom_Automatique( false );
1749  Refresh();
1750 }
1751 
1752 
1754 {
1755  int scale = 0;
1756  Kiface().KifaceSettings()->Read( LibIconScaleEntry, &scale, 0 );
1757  return scale;
1758 }
1759 
1760 
1762 {
1763  Kiface().KifaceSettings()->Write( LibIconScaleEntry, aScale );
1764  ReCreateMenuBar();
1765  ReCreateVToolbar();
1766  ReCreateHToolbar();
1768  Layout();
1769  SendSizeEvent();
1770 }
void OnViewEntryDoc(wxCommandEvent &event)
EDA_PANEINFO & HorizontalToolbarPane()
Function HorizontalToolbarPane Change *this to a horizontal toolbar for KiCad.
Definition: wxstruct.h:500
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
bool IsValid() const
Definition: lib_id.h:155
int GetCount() const
Function GetCount returns the number of objects in the list.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
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:45
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
void OnToggleSearchTree(wxCommandEvent &event)
#define KICAD_DEFAULT_DRAWFRAME_STYLE
Definition: wxstruct.h:55
void OnUpdateEditingPart(wxUpdateUIEvent &event)
bool UnitsLocked() const
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:282
void SaveOneSymbol()
Saves the current symbol to a symbol file.
Definition: symbedit.cpp:155
void OnUpdateSaveLib(wxUpdateUIEvent &event)
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.
Definition: libeditframe.h:129
Part library alias object definition.
bool IsMulti() const
std::unique_ptr< LIB_PART > m_copiedPart
Definition: libeditframe.h:766
CMP_TREE_MODEL_ADAPTER_BASE::PTR & GetAdapter()
Returns the adapter object that provides the stored data.
Definition: lib_manager.h:225
void ReCreateOptToolbar()
Definition: tool_lib.cpp:224
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
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
void StartMovePin(wxDC *DC)
Prepare the displacement of a pin.
Definition: pinedit.cpp:334
PNG memory record (file in memory).
Definition: bitmap_types.h:41
#define MAX_SELECT_ITEM_IDS
The maximum number of items in the clarify selection context menu.
Definition: eeschema_id.h:41
virtual void OnEditSymbolLibTable(wxCommandEvent &aEvent)
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
static int m_convert
Definition: libeditframe.h:116
bool m_showAxis
True shows the X and Y axis indicators.
Definition: draw_frame.h:103
void RestoreComponent()
Restore the current edited component from its temporary copy.
LIB_ALIAS * GetAlias(size_t aIndex)
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:332
bool IsSearchTreeShown()
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:334
void OnUpdateClipboardNotEmpty(wxUpdateUIEvent &aEvent)
bool RemovePart(const wxString &aName, const wxString &aLibrary)
Removes the part from the part buffer.
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
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:173
double BestZoom() override
Return the zoom level which displays the full page on screen.
This file is part of the common library.
void SetScreen(BASE_SCREEN *aScreen)
Definition: draw_frame.h:144
void SetScrollCenterPosition(const wxPoint &aPoint)
bool isCurrentPart(const LIB_ID &aLibId) const
Returns true if currently modified part has the same LIB_ID.
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:85
LIB_MANAGER * m_libMgr
manager taking care of temporary modificatoins
Definition: libeditframe.h:67
void OnUpdateUndo(wxUpdateUIEvent &event)
struct EDA_HOTKEY_CONFIG g_Libedit_Hokeys_Descr[]
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
void OnUpdatePartModified(wxUpdateUIEvent &aEvent)
int GetHeight() const
void GlobalSetPins(LIB_PIN *aMasterPin, int aId)
Definition: pinedit.cpp:552
wxString SchematicLibraryFileWildcard()
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:86
void OnUpdateSaveLibAs(wxUpdateUIEvent &event)
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
Definition: basicframe.cpp:365
void OnModify()
Must be called after a schematic change in order to set the "modify" flag of the current screen...
void OnSelectBodyStyle(wxCommandEvent &event)
void OnUpdateDeMorganNormal(wxUpdateUIEvent &event)
void LoadOneSymbol()
Read a component symbol file (*.sym ) and add graphic items to the current component.
Definition: symbedit.cpp:48
SYMBOL_LIB_TABLE * selectSymLibTable()
Displays a dialog asking the user to select a symbol library table.
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
Definition: wxstruct.h:149
FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::ProcessPreferences FOOTPRINT_EDIT_FRAME::ProcessPreferences FOOTPRINT_EDIT_FRAME::ProcessPreferences FOOTPRINT_EDIT_FRAME::ProcessPreferences FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard FOOTPRINT_EDIT_FRAME::OnUpdateReplaceModuleInBoard EVT_UPDATE_UI_RANGE(ID_MODEDIT_PAD_TOOL, ID_MODEDIT_MEASUREMENT_TOOL, FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar) EVT_UPDATE_UI(ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH
void SetIconScale(int aScale) override
Function SetIconScale.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
size_t GetAliasCount() const
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:54
void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
Definition: draw_panel.cpp:354
void OnUpdatePaste(wxUpdateUIEvent &event)
void OnUpdateDeMorganConvert(wxUpdateUIEvent &event)
void UpdateAliasSelectList()
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.
Definition: libeditframe.h:61
Specialization of the wxAuiPaneInfo class for KiCad panels.
Definition: wxstruct.h:491
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
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:66
void SetShowDeMorgan(bool show)
Definition: libeditframe.h:446
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::Process_Config EDA_BASE_FRAME::OnSelectPreferredEditor EVT_COMBOBOX(ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnSelectActiveLayer) EVT_MENU_RANGE(ID_POPUP_GENERAL_START_RANGE
void OnOrient(wxCommandEvent &aEvent)
Handles the ID_LIBEDIT_MIRROR_X and ID_LIBEDIT_MIRROR_Y events.
void DisplayLibInfos()
Updates the main window title bar with the current library name and read only status of the library...
Definition: libedit.cpp:59
void OnEditComponentProperties(wxCommandEvent &event)
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:59
virtual bool HandleBlockBegin(wxDC *aDC, EDA_KEY aKey, const wxPoint &aPosition, int aExplicitCommand=0)
Initialize a block command.
Definition: draw_frame.cpp:838
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
void Zoom_Automatique(bool aWarpPointer)
Function Zoom_Automatique redraws the screen with best zoom level and the best centering that shows a...
Definition: zoom.cpp:77
EDA_PANEINFO & VerticalToolbarPane()
Function VerticalToolbarPane Change *this to a vertical toolbar for KiCad.
Definition: wxstruct.h:518
bool saveAllLibraries()
Returns true when the operation has succeded (all requested libraries have been saved or none was sel...
Definition: libedit.cpp:591
bool AddLibrary(const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
Adds an existing library.
Definition: lib_manager.h:93
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.
Definition: libeditframe.h:166
wxAuiToolBar * m_optionsToolBar
The options tool bar typcially located on the left edge of the main window.
Definition: draw_frame.h:129
LIB_EDIT_FRAME(KIWAY *aKiway, wxWindow *aParent)
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:280
EDA_HOTKEY_CONFIG * m_hotkeysDescrList
Definition: draw_frame.h:77
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit components, if the user selects the component itself rather than picking an individual...
void Refresh()
Update the board display after modifying it bu a python script (note: it is automatically called by a...
void ReCreateMenuBar() override
(Re)Create the menubar for the part editor frame
void SetDrawItem(LIB_ITEM *drawItem)
Definition: libeditframe.h:442
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:788
LIB_COLLECTOR m_collectedItems
Used for hit testing.
Definition: libeditframe.h:63
bool m_Center
Center on screen.
bool IsMouseCaptured() const
EDA_MSG_PANEL * m_messagePanel
Panel used to display information at the bottom of the main window.
Definition: draw_frame.h:132
void OnUpdateSelectAlias(wxUpdateUIEvent &event)
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
void deleteItem(wxDC *aDC)
Deletes the currently selected draw item.
void OnUpdateViewDoc(wxUpdateUIEvent &event)
void OnUpdatePinTable(wxUpdateUIEvent &event)
wxFileName getLibraryFileName(bool aExisting)
Displays a file browser dialog to select a library file.
wxComboBox * m_partSelectBox
a Box to select a part to edit (if any)
Definition: libeditframe.h:64
EVT_MENU(ID_SELECT_PREFERED_PDF_BROWSER_NAME, KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser) EVT_MENU_RANGE(ID_LANGUAGE_CHOICE
bool LibraryExists(const wxString &aLibrary) const
Returns true if library exists.
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.
LIB_ITEM * locateItem(const wxPoint &aPosition, const KICAD_T aFilterList[])
#define LIB_EDIT_FRAME_NAME
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.
bool IsMenuActive() const
Returns the status of right-click context menu.
The common library.
unsigned STATUS_FLAGS
Definition: base_struct.h:158
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.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
bool IsLibraryModified(const wxString &aLibrary) const
Returns true if library has unsaved modifications.
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.
Definition: libeditframe.h:132
wxPoint m_FramePos
Definition: wxstruct.h:139
static LIB_ITEM * m_lastDrawItem
Definition: libeditframe.h:108
void SetCurrentLib(const wxString &aLibrary)
Sets the currently modified library name.
Definition: lib_manager.h:238
void OnUpdatePinByPin(wxUpdateUIEvent &event)
LIB_EDIT_FRAME::Process_Config LIB_EDIT_FRAME::Process_Special_Functions ID_LIBEDIT_DELETE_ITEM_BUTT
int m_UndoRedoCountMax
default Undo/Redo command Max depth, to be handed
Definition: draw_frame.h:89
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.
Definition: libeditframe.h:126
void SetCurrentPart(const wxString &aPart)
Sets the currently modified part name.
Definition: lib_manager.h:254
void SetAutoPanRequest(bool aEnable)
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg)
Function SetToolID sets the tool command ID to aId and sets the cursor to aCursor.
Definition: draw_frame.cpp:547
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)
void OnShowElectricalType(wxCommandEvent &event)
From Option toolbar: option to show the electrical pin type name.
int m_LastGridSizeId
Definition: draw_frame.h:78
void StartModifyDrawSymbol(wxDC *DC)
Definition: symbdraw.cpp:321
void CrossHairOff(wxDC *DC)
Definition: draw_panel.cpp:259
The the schematic editor to refresh the display.
Definition: mail_type.h:47
friend class DIALOG_LIB_EDIT_TEXT
Definition: libeditframe.h:145
wxAuiToolBar * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:126
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:145
void OnRotateItem(wxCommandEvent &aEvent)
Rotates the current item.
const wxChar LibIconScaleEntry[]
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.
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:232
EVT_TOOL_RANGE(ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_DELETE_ITEM_BUTT, LIB_EDIT_FRAME::OnSelectTool) EVT_MENU_RANGE(ID_PREFERENCES_HOTKEY_START
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:632
void SelectLibId(const LIB_ID &aLibId)
Select a part in the tree widget.
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
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
LIB_PART * GetPart() const
Get the shared LIB_PART.
void SetShowElectricalType(bool aShow)
Definition: libeditframe.h:450
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:450
int GetUnitCount() const
ID_PREFERENCES_HOTKEY_END
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.
Definition: libeditframe.h:135
Class to handle modifications to the symbol libraries.
Definition: lib_manager.h:48
void EditSymbolText(wxDC *DC, LIB_ITEM *DrawItem)
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)
Definition: draw_frame.cpp:572
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:93
void OnSelectItem(wxCommandEvent &aEvent)
void OnOpenPinTable(wxCommandEvent &aEvent)
void SetUnit(int aUnit)
wxString getTargetLib() const
Returns either the library selected in the component tree, if context menu is active or the library t...
wxString GetDocFileName() const
#define GR_DEFAULT_DRAWMODE
Definition: general.h:70
void OnUpdateSelectTool(wxUpdateUIEvent &aEvent)
bool GetAbortRequest() const
VTBL_ENTRY const wxString & GetRString(RSTRING_T aStringId)
Function GetRString returns a "retained string", which is any session and project specific string ide...
Definition: project.cpp:186
LIB_ITEM * LocateItemUsingCursor(const wxPoint &aPosition, const KICAD_T aFilterList[]=LIB_COLLECTOR::AllItems)
EDA_PANEINFO & MessageToolbarPane()
Function MessageToolbarPane Change *this to a message pane for KiCad.
Definition: wxstruct.h:537
void CrossHairOn(wxDC *DC)
Definition: draw_panel.cpp:266
virtual void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Function GetNearestGridPosition returns the nearest aGridSize location to aPosition.
The symbol library editor main window.
Definition: libeditframe.h:59
const int scale
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
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
BLOCK_SELECTOR m_clipboard
Clipboard buffer storing LIB_ITEMs
Definition: libeditframe.h:763
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:58
void ReCreateHToolbar() override
Definition: tool_lib.cpp:94
BASE_SCREEN class implementation.
static wxString m_aliasName
Definition: libeditframe.h:109
bool GetShowDeMorgan()
Definition: libeditframe.h:444
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
Definition: libeditframe.h:112
void TestDanglingEnds()
LIB_ITEM * GetCurLibItem() const
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
void SetCurPart(LIB_PART *aPart)
Take ownership of aPart and notes that it is the one currently being edited.
void OnSelectAlias(wxCommandEvent &event)
#define max(a, b)
Definition: auxiliary.h:86
VTBL_ENTRY void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, const std::string &aPayload, wxWindow *aSource=NULL)
Function ExpressMail send aPayload to aDestination from aSource.
Definition: kiway.cpp:386
KICAD_MANAGER_FRAME::language_change KICAD_MANAGER_FRAME::OnChangeIconsOptions EVT_UPDATE_UI(ID_SELECT_PREFERED_PDF_BROWSER, KICAD_MANAGER_FRAME::OnUpdatePreferredPdfBrowser) EVT_UPDATE_UI_RANGE(ID_TO_SCH
#define INSTALL_UNBUFFERED_DC(name, parent)
virtual void HandleBlockPlace(wxDC *DC) override
Handles the block place command.
int GetToolId() const
Definition: draw_frame.h:468
static FILL_T m_drawFillStyle
The current draw or edit graphic item fill style.
Definition: libeditframe.h:103
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
Definition: wxstruct.h:117
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
void EndDrawGraphicItem(wxDC *DC)
Definition: symbdraw.cpp:350
LIB_ITEM * GetDrawItem() const
Definition: libeditframe.h:440
void SetIgnoreMouseEvents(bool aIgnore)
bool m_editPinsSeparately
Set to true to not synchronize pins at the same position when editing symbols with multiple units or ...
Definition: libeditframe.h:95
Class EDA_RECT handles the component boundary box.
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Library Editor pane with component tree and symbol library table selector.
Definition: cmp_tree_pane.h:40
void SetMaxUndoItems(int aMax)
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.
Definition: libeditframe.h:138
void EditGraphicSymbol(wxDC *DC, LIB_ITEM *DrawItem)
Definition: symbdraw.cpp:58
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 GetIconScale() override
Function GetIconScale.
void Regenerate()
Updates the component tree
int GetWidth() const
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.
void SyncLibraries(bool aLoad)
Synchronize the library manager and the symbol library table.
void SetEnableBlockCommands(bool aEnable)
int m_repeatPinStep
Default repeat offset for pins in repeat place pin.
Definition: libeditframe.h:141
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:70
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:281
const wxString & GetName() const
bool SynchronizePins()
Pin edition (add, delete, move...) can be synchronized between units when units are interchangeable b...
void OnUpdateElectricalType(wxUpdateUIEvent &aEvent)
bool IsEditingDrawItem()
Definition: libeditframe.h:477
const PAGE_INFO & GetPageSettings() const
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
Definition: libeditframe.h:705
LIB_EDIT_FRAME::Process_Config ID_POPUP_GENERAL_END_RANGE
void EditField(LIB_FIELD *Field)
Definition: libfield.cpp:44
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.
Definition: libeditframe.h:106
bool m_drawSpecificConvert
Convert of the item currently being drawn.
Definition: libeditframe.h:70
LIB_EDIT_FRAME::Process_Config EVT_MENU_RANGE(ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_ITEM, ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT, LIB_EDIT_FRAME::Process_Special_Functions) EVT_MENU_RANGE(ID_POPUP_GENERAL_START_RANGE
wxSize m_FrameSize
Definition: wxstruct.h:140
COMPONENT_TREE * GetCmpTree() const
Definition: cmp_tree_pane.h:46
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
Definition: libeditframe.h:123
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:98
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Function SetCrossHairPosition sets the screen cross hair position to aPosition in logical (drawing) u...
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
bool m_drawSpecificUnit
Specify which component parts the current draw item applies to.
Definition: libeditframe.h:78
Message panel definition file.
int SelectSingleOption(wxWindow *aParent, const wxString &aTitle, const wxString &aMessage, const wxArrayString &aOptions)
Displays a dialog with radioboxes asking the user to select an option.
Definition: confirm.cpp:173
void OnSelectPart(wxCommandEvent &event)
int GetDefaultCursor() const
Function GetDefaultCursor.
const wxString SchematicLibraryFileExtension
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:74
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
void UpdatePartSelectList()
unsigned GetCount() const
virtual void OnActivate(wxActivateEvent &event)
Function OnActivate (virtual) is called when activating the frame.
Definition: draw_frame.cpp:269
LIB_PART * getTargetPart() const
Returns currently edited part.
void StartMoveDrawSymbol(wxDC *DC)
Definition: symbdraw.cpp:298
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:779
static wxSize m_clientSize
Definition: libeditframe.h:143
Definition of class LIB_EDIT_FRAME.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
bool GetShowElectricalType()
Definition: libeditframe.h:448
std::vector< double > m_ZoomList
standard zoom (i.e. scale) coefficients.
int GetDefaultTextSize()
Default size for text in general.
void SetCommand(BLOCK_COMMAND_T aCommand)
CMP_TREE_PANE * m_treePane
component search tree widget
Definition: libeditframe.h:66
wxComboBox * m_aliasSelectBox
a box to select the alias to edit (if any)
Definition: libeditframe.h:65
void OnUpdateLibModified(wxUpdateUIEvent &aEvent)
int GetConvert() const
LIB_PART * m_tempCopyComponent
temp copy of a part during edit, I own it here.
Definition: libeditframe.h:62
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy)
Create a copy of the current component, and save it in the undo list.
void ReCreateVToolbar() override
Definition: tool_lib.cpp:48