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-2017 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2004-2017 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 <confirm.h>
36 #include <eda_doc.h>
37 #include <gr_basic.h>
38 #include <schframe.h>
39 #include <msgpanel.h>
40 
41 #include <general.h>
42 #include <eeschema_id.h>
43 #include <libeditframe.h>
44 #include <class_library.h>
45 #include <lib_polyline.h>
46 #include <lib_pin.h>
47 
48 #include <kicad_device_context.h>
49 #include <hotkeys.h>
50 
54 
55 #include <menus_helpers.h>
56 
57 
58 /* This method guarantees unique IDs for the library this run of Eeschema
59  * which prevents ID conflicts and eliminates the need to recompile every
60  * source file in the project when adding IDs to include/id.h. */
61 int ExportPartId = ::wxNewId();
62 int ImportPartId = ::wxNewId();
63 int CreateNewLibAndSavePartId = ::wxNewId();
64 
65 
72 wxSize LIB_EDIT_FRAME:: m_clientSize = wxSize( -1, -1 );
76 
77 // these values are overridden when reading the config
81 
83 
84 
85 BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
86  EVT_CLOSE( LIB_EDIT_FRAME::OnCloseWindow )
87  EVT_SIZE( LIB_EDIT_FRAME::OnSize )
88  EVT_ACTIVATE( LIB_EDIT_FRAME::OnActivate )
89 
90  // Main horizontal toolbar.
91  EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_LIB, LIB_EDIT_FRAME::OnSaveActiveLibrary )
92  EVT_TOOL( ID_LIBEDIT_SELECT_CURRENT_LIB, LIB_EDIT_FRAME::Process_Special_Functions )
94  EVT_TOOL( ID_TO_LIBVIEW, LIB_EDIT_FRAME::OnOpenLibraryViewer )
95  EVT_TOOL( ID_LIBEDIT_NEW_PART, LIB_EDIT_FRAME::CreateNewLibraryPart )
96  EVT_TOOL( ID_LIBEDIT_NEW_PART_FROM_EXISTING, LIB_EDIT_FRAME::OnCreateNewPartFromExisting )
97 
98  EVT_TOOL( ID_LIBEDIT_SELECT_PART, LIB_EDIT_FRAME::LoadOneLibraryPart )
99  EVT_TOOL( wxID_UNDO, LIB_EDIT_FRAME::GetComponentFromUndoList )
100  EVT_TOOL( wxID_REDO, LIB_EDIT_FRAME::GetComponentFromRedoList )
101  EVT_TOOL( ID_LIBEDIT_GET_FRAME_EDIT_PART, LIB_EDIT_FRAME::OnEditComponentProperties )
102  EVT_TOOL( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, LIB_EDIT_FRAME::InstallFieldsEditorDialog )
103  EVT_TOOL( ID_LIBEDIT_CHECK_PART, LIB_EDIT_FRAME::OnCheckComponent )
104  EVT_TOOL( ID_DE_MORGAN_NORMAL_BUTT, LIB_EDIT_FRAME::OnSelectBodyStyle )
105  EVT_TOOL( ID_DE_MORGAN_CONVERT_BUTT, LIB_EDIT_FRAME::OnSelectBodyStyle )
106  EVT_TOOL( ID_LIBEDIT_VIEW_DOC, LIB_EDIT_FRAME::OnViewEntryDoc )
107  EVT_TOOL( ID_LIBEDIT_EDIT_PIN_BY_PIN, LIB_EDIT_FRAME::Process_Special_Functions )
109  EVT_TOOL( ExportPartId, LIB_EDIT_FRAME::OnExportPart )
111  EVT_TOOL( ImportPartId, LIB_EDIT_FRAME::OnImportPart )
113 
114  EVT_COMBOBOX( ID_LIBEDIT_SELECT_PART_NUMBER, LIB_EDIT_FRAME::OnSelectPart )
115  EVT_COMBOBOX( ID_LIBEDIT_SELECT_ALIAS, LIB_EDIT_FRAME::OnSelectAlias )
116 
117  // Right vertical toolbar.
119  EVT_TOOL( ID_ZOOM_SELECTION, LIB_EDIT_FRAME::OnSelectTool )
121  LIB_EDIT_FRAME::OnSelectTool )
122 
123  // Left vertical toolbar (option toolbar).
125 
126  // menubar commands
127  EVT_MENU( wxID_EXIT, LIB_EDIT_FRAME::CloseWindow )
129  EVT_MENU( ID_LIBEDIT_GEN_PNG_FILE, LIB_EDIT_FRAME::OnPlotCurrentComponent )
130  EVT_MENU( ID_LIBEDIT_GEN_SVG_FILE, LIB_EDIT_FRAME::OnPlotCurrentComponent )
131  EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
132  EVT_MENU( wxID_INDEX, EDA_DRAW_FRAME::GetKicadHelp )
133  EVT_MENU( ID_HELP_GET_INVOLVED, EDA_DRAW_FRAME::GetKicadContribute )
134  EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout )
135 
136  EVT_MENU( wxID_PREFERENCES, LIB_EDIT_FRAME::OnPreferencesOptions )
137  EVT_MENU( ID_CONFIG_REQ, LIB_EDIT_FRAME::InstallConfigFrame )
138 
139  // Multiple item selection context menu commands.
141 
143  LIB_EDIT_FRAME::Process_Config )
144 
145  // Context menu events and commands.
148 
151  LIB_EDIT_FRAME::Process_Special_Functions )
152 
154  LIB_EDIT_FRAME::Process_Special_Functions )
155 
157  LIB_EDIT_FRAME::OnOrient )
158  // Update user interface elements.
159  EVT_UPDATE_UI( ExportPartId, LIB_EDIT_FRAME::OnUpdateEditingPart )
160  EVT_UPDATE_UI( CreateNewLibAndSavePartId, LIB_EDIT_FRAME::OnUpdateEditingPart )
161  EVT_UPDATE_UI( ID_LIBEDIT_SAVE_CURRENT_PART, LIB_EDIT_FRAME::OnUpdateEditingPart )
162  EVT_UPDATE_UI( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, LIB_EDIT_FRAME::OnUpdateEditingPart )
163  EVT_UPDATE_UI( ID_LIBEDIT_CHECK_PART, LIB_EDIT_FRAME::OnUpdateEditingPart )
164  EVT_UPDATE_UI( ID_LIBEDIT_GET_FRAME_EDIT_PART, LIB_EDIT_FRAME::OnUpdateEditingPart )
165  EVT_UPDATE_UI( ID_LIBEDIT_NEW_PART_FROM_EXISTING, LIB_EDIT_FRAME::OnUpdateEditingPart )
166  EVT_UPDATE_UI( wxID_UNDO, LIB_EDIT_FRAME::OnUpdateUndo )
167  EVT_UPDATE_UI( wxID_REDO, LIB_EDIT_FRAME::OnUpdateRedo )
168  EVT_UPDATE_UI( ID_LIBEDIT_SAVE_CURRENT_LIB, LIB_EDIT_FRAME::OnUpdateSaveCurrentLib )
169  EVT_UPDATE_UI( ID_LIBEDIT_SAVE_CURRENT_LIB_AS, LIB_EDIT_FRAME::OnUpdateSaveCurrentLib )
170  EVT_UPDATE_UI( ID_LIBEDIT_VIEW_DOC, LIB_EDIT_FRAME::OnUpdateViewDoc )
171  EVT_UPDATE_UI( ID_LIBEDIT_EDIT_PIN_BY_PIN, LIB_EDIT_FRAME::OnUpdatePinByPin )
172  EVT_UPDATE_UI( ID_LIBEDIT_EDIT_PIN_BY_TABLE, LIB_EDIT_FRAME::OnUpdatePinTable )
173  EVT_UPDATE_UI( ID_LIBEDIT_SELECT_PART_NUMBER, LIB_EDIT_FRAME::OnUpdatePartNumber )
174  EVT_UPDATE_UI( ID_LIBEDIT_SELECT_ALIAS, LIB_EDIT_FRAME::OnUpdateSelectAlias )
175  EVT_UPDATE_UI( ID_DE_MORGAN_NORMAL_BUTT, LIB_EDIT_FRAME::OnUpdateDeMorganNormal )
176  EVT_UPDATE_UI( ID_DE_MORGAN_CONVERT_BUTT, LIB_EDIT_FRAME::OnUpdateDeMorganConvert )
177  EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, LIB_EDIT_FRAME::OnUpdateEditingPart )
178  EVT_UPDATE_UI( ID_ZOOM_SELECTION, LIB_EDIT_FRAME::OnUpdateEditingPart )
179  EVT_UPDATE_UI_RANGE( ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_DELETE_ITEM_BUTT,
180  LIB_EDIT_FRAME::OnUpdateEditingPart )
181  EVT_UPDATE_UI( ID_LIBEDIT_SHOW_ELECTRICAL_TYPE, LIB_EDIT_FRAME::OnUpdateElectricalType )
182 
183 END_EVENT_TABLE()
184 
185 #define LIB_EDIT_FRAME_NAME wxT( "LibeditFrame" )
186 
187 LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
188  SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_LIB_EDITOR, _( "Library Editor" ),
189  wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, LIB_EDIT_FRAME_NAME )
190 {
191  m_showAxis = true; // true to draw axis
192  SetShowDeMorgan( false );
193  m_drawSpecificConvert = true;
194  m_drawSpecificUnit = false;
198  SetShowElectricalType( true );
199 
200  m_my_part = NULL;
201  m_tempCopyComponent = NULL;
202 
203  // Delayed initialization
204  if( m_textSize == -1 )
206 
207  // Initialize grid id to the default value 50 mils:
209 
210  wxIcon icon;
211  icon.CopyFromBitmap( KiBitmap( icon_libedit_xpm ) );
212  SetIcon( icon );
213 
214  LoadSettings( config() );
215 
216  SetScreen( new SCH_SCREEN( aKiway ) );
217  GetScreen()->m_Center = true;
219 
220  SetCrossHairPosition( wxPoint( 0, 0 ) );
221 
222  // Ensure m_LastGridSizeId is an offset inside the allowed schematic range
223  if( m_LastGridSizeId < ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000 )
225 
226  if( m_LastGridSizeId > ID_POPUP_GRID_LEVEL_1 - ID_POPUP_GRID_LEVEL_1000 )
228 
229  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
230 
231  GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
232 
233  if( m_canvas )
235 
236  ReCreateMenuBar();
239 
240  // Ensure the current alias name is valid if a part is loaded
241  // Sometimes it is not valid. This is the case
242  // when a part value (the part lib name), or the alias list was modified
243  // during a previous session and the modifications not saved in lib.
244  // Reopen libedit in a new session gives a non valid m_aliasName
245  // because the curr part is reloaded from the library (and this is the unmodified part)
246  // and the old alias name (from the previous edition) can be invalid
247  LIB_PART* part = GetCurPart();
248 
249  if( part == NULL )
250  m_aliasName.Empty();
251  else if( m_aliasName != part->GetName() )
252  {
253  LIB_ALIAS* alias = part->GetAlias( m_aliasName );
254 
255  if( !alias )
256  m_aliasName = part->GetName();
257  }
258 
259 
261  DisplayLibInfos();
262  DisplayCmpDoc();
265 
266  m_auimgr.SetManagedWindow( this );
267 
268  EDA_PANEINFO horiz;
269  horiz.HorizontalToolbarPane();
270 
271  EDA_PANEINFO vert;
272  vert.VerticalToolbarPane();
273 
274  EDA_PANEINFO mesg;
275  mesg.MessageToolbarPane();
276 
277  m_auimgr.AddPane( m_mainToolBar,
278  wxAuiPaneInfo( horiz ).Name( "m_mainToolBar" ).Top().Row( 0 ) );
279 
280  m_auimgr.AddPane( m_drawToolBar,
281  wxAuiPaneInfo( vert ).Name( "m_VToolBar" ).Right() );
282 
283  m_auimgr.AddPane( m_optionsToolBar,
284  wxAuiPaneInfo( vert ).Name( "m_optionsToolBar" ).Left() );
285 
286  m_auimgr.AddPane( m_canvas,
287  wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
288 
289  m_auimgr.AddPane( m_messagePanel,
290  wxAuiPaneInfo( mesg ).Name( "MsgPanel" ).Bottom().Layer(10) );
291 
292  m_auimgr.Update();
293 
294  Raise();
295  Show( true );
296 
297  wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, ID_ZOOM_PAGE );
298  wxPostEvent( this, evt );
299 }
300 
301 
303 {
304  m_drawItem = m_lastDrawItem = NULL;
305 
306  delete m_tempCopyComponent;
307  delete m_my_part;
308  m_my_part = NULL;
309  m_tempCopyComponent = NULL;
310 }
311 
312 
314 {
315  m_drawItem = drawItem;
316 }
317 
318 
319 void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
320 {
321  if( GetScreen()->IsModify() )
322  {
323  int ii = DisplayExitDialog( this, _( "Save the changes in the library before closing?" ) );
324 
325  switch( ii )
326  {
327  case wxID_NO:
328  break;
329 
330  case wxID_YES:
331  if ( this->SaveActiveLibrary( false ) )
332  break;
333 
334  // fall through: cancel the close because of an error
335 
336  case wxID_CANCEL:
337  Event.Veto();
338  return;
339  }
340  GetScreen()->ClrModify();
341  }
342 
343  PART_LIBS* libs = Prj().SchLibs();
344 
345  for( const PART_LIB& lib : *libs )
346  {
347  if( lib.IsModified() )
348  {
349  wxString msg = wxString::Format( _(
350  "Library '%s' was modified!\nDiscard changes?" ),
351  GetChars( lib.GetName() )
352  );
353 
354  if( !IsOK( this, msg ) )
355  {
356  Event.Veto();
357  return;
358  }
359  }
360  }
361 
362  Destroy();
363 }
364 
365 
367 {
368  /* Please, note: wxMSW before version 2.9 seems have
369  * problems with zoom values < 1 ( i.e. userscale > 1) and needs to be patched:
370  * edit file <wxWidgets>/src/msw/dc.cpp
371  * search for line static const int VIEWPORT_EXTENT = 1000;
372  * and replace by static const int VIEWPORT_EXTENT = 10000;
373  */
374  int dx, dy;
375 
376  LIB_PART* part = GetCurPart();
377 
378  if( part )
379  {
381 
382  dx = boundingBox.GetWidth();
383  dy = boundingBox.GetHeight();
384  SetScrollCenterPosition( wxPoint( 0, 0 ) );
385  }
386  else
387  {
388  const PAGE_INFO& pageInfo = GetScreen()->GetPageSettings();
389 
390  dx = pageInfo.GetSizeIU().x;
391  dy = pageInfo.GetSizeIU().y;
392 
393  SetScrollCenterPosition( wxPoint( 0, 0 ) );
394  }
395 
396  wxSize size = m_canvas->GetClientSize();
397 
398  // Reserve a 10% margin around component bounding box.
399  double margin_scale_factor = 0.8;
400  double zx =(double) dx / ( margin_scale_factor * (double)size.x );
401  double zy = (double) dy / ( margin_scale_factor * (double)size.y );
402 
403  double bestzoom = std::max( zx, zy );
404 
405  // keep it >= minimal existing zoom (can happen for very small components
406  // for instance when starting a new component
407  if( bestzoom < GetScreen()->m_ZoomList[0] )
408  bestzoom = GetScreen()->m_ZoomList[0];
409 
410  return bestzoom;
411 }
412 
413 
415 {
416  if( m_aliasSelectBox == NULL )
417  return;
418 
419  m_aliasSelectBox->Clear();
420 
421  LIB_PART* part = GetCurPart();
422 
423  if( !part )
424  return;
425 
426  m_aliasSelectBox->Append( part->GetAliasNames() );
427  m_aliasSelectBox->SetSelection( 0 );
428 
429  int index = m_aliasSelectBox->FindString( m_aliasName );
430 
431  if( index != wxNOT_FOUND )
432  m_aliasSelectBox->SetSelection( index );
433 }
434 
435 
437 {
438  if( m_partSelectBox == NULL )
439  return;
440 
441  if( m_partSelectBox->GetCount() != 0 )
442  m_partSelectBox->Clear();
443 
444  LIB_PART* part = GetCurPart();
445 
446  if( !part || part->GetUnitCount() <= 1 )
447  {
448  m_unit = 1;
449  m_partSelectBox->Append( wxEmptyString );
450  }
451  else
452  {
453  for( int i = 0; i < part->GetUnitCount(); i++ )
454  {
455  wxString sub = LIB_PART::SubReference( i+1, false );
456  wxString unit = wxString::Format( _( "Unit %s" ), GetChars( sub ) );
457  m_partSelectBox->Append( unit );
458  }
459  }
460 
461  // Ensure the current selected unit is compatible with
462  // the number of units of the current part:
463  if( part && part->GetUnitCount() < m_unit )
464  m_unit = 1;
465 
466  m_partSelectBox->SetSelection( ( m_unit > 0 ) ? m_unit - 1 : 0 );
467 }
468 
469 
470 void LIB_EDIT_FRAME::OnShowElectricalType( wxCommandEvent& event )
471 {
473  GetCanvas()->Refresh();
474 }
475 
476 
477 void LIB_EDIT_FRAME::OnUpdateElectricalType( wxUpdateUIEvent& aEvent )
478 {
479  aEvent.Check( GetShowElectricalType() );
480 }
481 
482 
483 void LIB_EDIT_FRAME::OnUpdateEditingPart( wxUpdateUIEvent& aEvent )
484 {
485  LIB_PART* part = GetCurPart();
486 
487  aEvent.Enable( part != NULL );
488 
489  if( part && aEvent.GetEventObject() == m_drawToolBar )
490  aEvent.Check( GetToolId() == aEvent.GetId() );
491 }
492 
493 
494 void LIB_EDIT_FRAME::OnUpdateNotEditingPart( wxUpdateUIEvent& event )
495 {
496  event.Enable( !GetCurPart() );
497 }
498 
499 
500 void LIB_EDIT_FRAME::OnUpdateUndo( wxUpdateUIEvent& event )
501 {
502  event.Enable( GetCurPart() && GetScreen() &&
503  GetScreen()->GetUndoCommandCount() != 0 && !IsEditingDrawItem() );
504 }
505 
506 
507 void LIB_EDIT_FRAME::OnUpdateRedo( wxUpdateUIEvent& event )
508 {
509  event.Enable( GetCurPart() && GetScreen() &&
510  GetScreen()->GetRedoCommandCount() != 0 && !IsEditingDrawItem() );
511 }
512 
513 
514 void LIB_EDIT_FRAME::OnUpdateSaveCurrentLib( wxUpdateUIEvent& event )
515 {
516  PART_LIB* lib = GetCurLib();
517 
518  event.Enable( lib && !lib->IsReadOnly()
519  && ( lib->IsModified() || GetScreen()->IsModify() ) );
520 }
521 
522 
523 void LIB_EDIT_FRAME::OnUpdateViewDoc( wxUpdateUIEvent& event )
524 {
525  bool enable = false;
526 
527  PART_LIB* lib = GetCurLib();
528  LIB_PART* part = GetCurPart();
529 
530  if( part && lib )
531  {
532  LIB_ALIAS* alias = part->GetAlias( m_aliasName );
533 
534  wxCHECK_RET( alias != NULL, wxT( "Alias <" ) + m_aliasName + wxT( "> not found." ) );
535 
536  enable = !alias->GetDocFileName().IsEmpty();
537  }
538 
539  event.Enable( enable );
540 }
541 
542 
543 void LIB_EDIT_FRAME::OnUpdatePinByPin( wxUpdateUIEvent& event )
544 {
545  LIB_PART* part = GetCurPart();
546 
547  event.Enable( part && ( part->GetUnitCount() > 1 || m_showDeMorgan ) );
548 
549  event.Check( m_editPinsPerPartOrConvert );
550 }
551 
552 
553 void LIB_EDIT_FRAME::OnUpdatePinTable( wxUpdateUIEvent& event )
554 {
555  LIB_PART* part = GetCurPart();
556  event.Enable( part != NULL );
557 }
558 
559 
560 void LIB_EDIT_FRAME::OnUpdatePartNumber( wxUpdateUIEvent& event )
561 {
562  if( m_partSelectBox == NULL )
563  return;
564 
565  LIB_PART* part = GetCurPart();
566 
567  // Using the typical event.Enable() call doesn't seem to work with wxGTK
568  // so use the pointer to alias combobox to directly enable or disable.
569  m_partSelectBox->Enable( part && part->GetUnitCount() > 1 );
570 }
571 
572 
573 void LIB_EDIT_FRAME::OnUpdateDeMorganNormal( wxUpdateUIEvent& event )
574 {
575  if( m_mainToolBar == NULL )
576  return;
577 
578  LIB_PART* part = GetCurPart();
579 
580  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
581  event.Check( m_convert <= 1 );
582 }
583 
584 
585 void LIB_EDIT_FRAME::OnUpdateDeMorganConvert( wxUpdateUIEvent& event )
586 {
587  if( m_mainToolBar == NULL )
588  return;
589 
590  LIB_PART* part = GetCurPart();
591 
592  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
593  event.Check( m_convert > 1 );
594 }
595 
596 
597 void LIB_EDIT_FRAME::OnUpdateSelectAlias( wxUpdateUIEvent& event )
598 {
599  if( m_aliasSelectBox == NULL )
600  return;
601 
602  LIB_PART* part = GetCurPart();
603 
604  // Using the typical event.Enable() call doesn't seem to work with wxGTK
605  // so use the pointer to alias combobox to directly enable or disable.
606  m_aliasSelectBox->Enable( part && part->GetAliasCount() > 1 );
607 }
608 
609 
610 void LIB_EDIT_FRAME::OnSelectAlias( wxCommandEvent& event )
611 {
612  if( m_aliasSelectBox == NULL
613  || ( m_aliasSelectBox->GetStringSelection().CmpNoCase( m_aliasName ) == 0) )
614  return;
615 
616  m_lastDrawItem = NULL;
617  m_aliasName = m_aliasSelectBox->GetStringSelection();
618 
619  DisplayCmpDoc();
620  m_canvas->Refresh();
621 }
622 
623 
624 void LIB_EDIT_FRAME::OnSelectPart( wxCommandEvent& event )
625 {
626  int i = event.GetSelection();
627 
628  if( ( i == wxNOT_FOUND ) || ( ( i + 1 ) == m_unit ) )
629  return;
630 
631  m_lastDrawItem = NULL;
632  m_unit = i + 1;
633  m_canvas->Refresh();
634  DisplayCmpDoc();
635 }
636 
637 
638 void LIB_EDIT_FRAME::OnViewEntryDoc( wxCommandEvent& event )
639 {
640  LIB_PART* part = GetCurPart();
641 
642  if( !part )
643  return;
644 
645  wxString fileName;
646  LIB_ALIAS* alias = part->GetAlias( m_aliasName );
647 
648  wxCHECK_RET( alias != NULL, "Alias not found." );
649 
650  fileName = alias->GetDocFileName();
651 
652  if( !fileName.IsEmpty() )
653  {
654  SEARCH_STACK* lib_search = Prj().SchSearchS();
655 
656  GetAssociatedDocument( this, fileName, lib_search );
657  }
658 }
659 
660 
661 void LIB_EDIT_FRAME::OnSelectBodyStyle( wxCommandEvent& event )
662 {
663  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
664 
665  if( event.GetId() == ID_DE_MORGAN_NORMAL_BUTT )
666  m_convert = 1;
667  else
668  m_convert = 2;
669 
670  m_lastDrawItem = NULL;
671  m_canvas->Refresh();
672 }
673 
674 
675 void LIB_EDIT_FRAME::OnSaveCurrentPart( wxCommandEvent& aEvent )
676 {
677  LIB_PART* part = GetCurPart();
678 
679  if( !part )
680  {
681  DisplayError( this, _( "No part to save." ) );
682  return;
683  }
684 
685  PART_LIB* lib = GetCurLib();
686 
687  if( !lib )
689 
690  lib = GetCurLib();
691 
692  if( !lib )
693  {
694  DisplayError( this, _( "No library specified." ) );
695  return;
696  }
697 
698  try
699  {
700  SaveOnePart( lib );
701  }
702  catch( ... )
703  {
704  wxString msg;
705  msg.Printf( _( "Unexpected error occured saving symbol '%s' to symbol library '%s'." ),
706  part->GetName(), lib->GetName() );
707  DisplayError( this, msg );
708  return;
709  }
710 
712 }
713 
714 
715 void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
716 {
717  int id = event.GetId();
718  wxPoint pos;
719 
721 
722  wxGetMousePosition( &pos.x, &pos.y );
723  pos.y += 20;
724 
725  switch( id ) // Stop placement commands before handling new command.
726  {
728  case ID_LIBEDIT_EDIT_PIN:
734  case ID_POPUP_ZOOM_BLOCK:
736  case ID_POPUP_COPY_BLOCK:
742  case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT:
743  break;
744 
746  if( m_canvas->IsMouseCaptured() )
748  else
749  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
750  break;
751 
754  break;
755 
756  default:
757  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(),
758  wxEmptyString );
759  break;
760  }
761 
763 
764  switch( id )
765  {
767  break;
768 
769  case ID_LIBEDIT_SELECT_CURRENT_LIB:
771  break;
772 
773  case ID_LIBEDIT_EDIT_PIN_BY_PIN:
774  m_editPinsPerPartOrConvert = m_mainToolBar->GetToolToggled( ID_LIBEDIT_EDIT_PIN_BY_PIN );
775  break;
776 
779  if( m_drawItem )
780  {
781  EndDrawGraphicItem( &dc );
782  }
783  break;
784 
786  if( m_drawItem )
787  {
788  m_canvas->CrossHairOff( &dc );
789 
790  switch( m_drawItem->Type() )
791  {
792  case LIB_ARC_T:
793  case LIB_CIRCLE_T:
794  case LIB_RECTANGLE_T:
795  case LIB_POLYLINE_T:
797  break;
798 
799  case LIB_TEXT_T:
800  EditSymbolText( &dc, m_drawItem );
801  break;
802 
803  default:
804  ;
805  }
806 
807  m_canvas->CrossHairOn( &dc );
808  }
809  break;
810 
811  case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT:
812  {
813  // Delete the last created segment, while creating a polyline draw item
814  if( m_drawItem == NULL )
815  break;
816 
818  STATUS_FLAGS oldFlags = m_drawItem->GetFlags();
820  m_drawItem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
822  ( (LIB_POLYLINE*) m_drawItem )->DeleteSegment( GetCrossHairPosition( true ) );
823  m_drawItem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
825  m_drawItem->SetFlags( oldFlags );
826  m_lastDrawItem = NULL;
827  }
828  break;
829 
831  if( m_drawItem )
832  deleteItem( &dc );
833 
834  break;
835 
837  if( m_drawItem == NULL )
838  break;
839 
840  if( m_drawItem->Type() == LIB_PIN_T )
841  StartMovePin( &dc );
842  else
843  StartMoveDrawSymbol( &dc );
844  break;
845 
847 
848  if( m_drawItem == NULL )
849  break;
850 
853  || m_drawItem->Type() == LIB_CIRCLE_T
855  || m_drawItem->Type() == LIB_ARC_T
856  )
857  {
858  StartModifyDrawSymbol( &dc );
859  }
860 
861  break;
862 
864  if( m_drawItem == NULL )
865  break;
866 
867  m_canvas->CrossHairOff( &dc );
868 
869  if( m_drawItem->Type() == LIB_FIELD_T )
870  {
872  }
873 
875  m_canvas->CrossHairOn( &dc );
876  break;
877 
881  {
882  if( !m_drawItem || m_drawItem->Type() != LIB_PIN_T )
883  break;
884 
885  LIB_PART* part = GetCurPart();
886 
887  SaveCopyInUndoList( part );
888 
889  GlobalSetPins( (LIB_PIN*) m_drawItem, id );
891  m_canvas->Refresh();
892  }
893  break;
894 
895  case ID_POPUP_ZOOM_BLOCK:
896  m_canvas->SetAutoPanRequest( false );
898  HandleBlockEnd( &dc );
899  break;
900 
902  m_canvas->SetAutoPanRequest( false );
905  HandleBlockEnd( &dc );
906  break;
907 
908  case ID_POPUP_COPY_BLOCK:
909  m_canvas->SetAutoPanRequest( false );
912  HandleBlockEnd( &dc );
913  break;
914 
916  m_canvas->SetAutoPanRequest( false );
919  HandleBlockEnd( &dc );
920  break;
921 
923  m_canvas->SetAutoPanRequest( false );
926  HandleBlockPlace( &dc );
927  break;
928 
930  m_canvas->SetAutoPanRequest( false );
933  HandleBlockPlace( &dc );
934  break;
935 
937  m_canvas->SetAutoPanRequest( false );
940  HandleBlockPlace( &dc );
941  break;
942 
944  m_canvas->SetAutoPanRequest( false );
946  HandleBlockPlace( &dc );
947  break;
948 
949  default:
950  DisplayError( this, "LIB_EDIT_FRAME::Process_Special_Functions error" );
951  break;
952  }
953 
954  m_canvas->SetIgnoreMouseEvents( false );
955 
956  if( GetToolId() == ID_NO_TOOL_SELECTED )
957  m_lastDrawItem = NULL;
958 }
959 
960 
961 void LIB_EDIT_FRAME::OnActivate( wxActivateEvent& event )
962 {
964 }
965 
966 
968 {
970 
971  if( !!name )
972  {
973  PART_LIB* lib = Prj().SchLibs()->FindLibrary( name );
974 
975  if( !lib )
976  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
977 
978  return lib;
979  }
980 
981  return NULL;
982 }
983 
984 
986 {
987  PART_LIB* old = GetCurLib();
988 
989  if( !aLib || !aLib->GetName() )
990  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
991  else
993 
994  return old;
995 }
996 
997 
999 {
1000  if( !m_my_part )
1001  {
1003  LIB_PART* part;
1004 
1005  if( !!name && ( part = Prj().SchLibs()->FindLibPart( LIB_ID( wxEmptyString, name ) ) ) )
1006  {
1007  // clone it from the PART_LIB and own it.
1008  m_my_part = new LIB_PART( *part );
1009  }
1010  else
1011  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_PART, wxEmptyString );
1012  }
1013 
1014  return m_my_part;
1015 }
1016 
1017 
1019 {
1020  delete m_my_part;
1021  m_my_part = aPart; // take ownership here
1022 
1023  // retain in case this wxFrame is re-opened later on the same PROJECT
1025  aPart ? aPart->GetName() : wxString() );
1026 }
1027 
1028 
1030 {
1031  delete m_tempCopyComponent;
1032 
1033  if( LIB_PART* part = GetCurPart() )
1034  // clone it and own the clone.
1035  m_tempCopyComponent = new LIB_PART( *part );
1036  else
1037  // clear it, there was no CurPart
1038  m_tempCopyComponent = NULL;
1039 }
1040 
1041 
1043 {
1044  if( m_tempCopyComponent )
1045  {
1046  // transfer ownership to CurPart
1048  m_tempCopyComponent = NULL;
1049  }
1050 }
1051 
1052 
1054 {
1055  delete m_tempCopyComponent;
1056  m_tempCopyComponent = NULL;
1057 }
1058 
1059 
1060 void LIB_EDIT_FRAME::EditSymbolText( wxDC* DC, LIB_ITEM* DrawItem )
1061 {
1062  if ( ( DrawItem == NULL ) || ( DrawItem->Type() != LIB_TEXT_T ) )
1063  return;
1064 
1065  // Deleting old text
1066  if( DC && !DrawItem->InEditMode() )
1067  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
1068  DefaultTransform );
1069 
1070  DIALOG_LIB_EDIT_TEXT* frame = new DIALOG_LIB_EDIT_TEXT( this, (LIB_TEXT*) DrawItem );
1071  frame->ShowModal();
1072  frame->Destroy();
1073  OnModify();
1074 
1075  // Display new text
1076  if( DC && !DrawItem->InEditMode() )
1077  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, GR_DEFAULT_DRAWMODE,
1078  NULL, DefaultTransform );
1079 }
1080 
1081 
1082 void LIB_EDIT_FRAME::OnEditComponentProperties( wxCommandEvent& event )
1083 {
1084  bool partLocked = GetCurPart()->UnitsLocked();
1085 
1087 
1088  if( dlg.ShowModal() == wxID_CANCEL )
1089  return;
1090 
1091  if( partLocked != GetCurPart()->UnitsLocked() )
1092  {
1093  // m_editPinsPerPartOrConvert is set to the better value, if m_UnitSelectionLocked
1094  // has changed
1095  m_editPinsPerPartOrConvert = GetCurPart()->UnitsLocked() ? true : false;
1096  }
1097 
1100  DisplayLibInfos();
1101  DisplayCmpDoc();
1102  OnModify();
1103  m_canvas->Refresh();
1104 }
1105 
1106 
1107 void LIB_EDIT_FRAME::OnCreateNewPartFromExisting( wxCommandEvent& event )
1108 {
1109  LIB_PART* part = GetCurPart();
1110 
1111  wxCHECK_RET( part, "Cannot create new part from non-existent current part." );
1112 
1114  m_canvas->CrossHairOff( &dc );
1115 
1116  EditField( &part->GetValueField() );
1117 
1119  m_canvas->CrossHairOn( &dc );
1120 }
1121 
1122 
1123 void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
1124 {
1125  int id = aEvent.GetId();
1126 
1127  if( GetToolId() == ID_NO_TOOL_SELECTED )
1128  m_lastDrawItem = NULL;
1129 
1130  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(),
1131  wxEmptyString );
1132 
1133  LIB_PART* part = GetCurPart();
1134 
1135  switch( id )
1136  {
1137  case ID_NO_TOOL_SELECTED:
1138  SetToolID( id, m_canvas->GetDefaultCursor(), wxEmptyString );
1139  break;
1140 
1141  case ID_ZOOM_SELECTION:
1142  SetToolID( id, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) );
1143  break;
1144 
1145  case ID_LIBEDIT_PIN_BUTT:
1146  if( part )
1147  {
1148  SetToolID( id, wxCURSOR_PENCIL, _( "Add pin" ) );
1149  }
1150  else
1151  {
1152  SetToolID( id, wxCURSOR_ARROW, _( "Set pin options" ) );
1153 
1154  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
1155 
1156  cmd.SetId( ID_LIBEDIT_EDIT_PIN );
1157  GetEventHandler()->ProcessEvent( cmd );
1158  SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
1159  }
1160  break;
1161 
1163  SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) );
1164  break;
1165 
1167  SetToolID( id, wxCURSOR_PENCIL, _( "Add rectangle" ) );
1168  break;
1169 
1171  SetToolID( id, wxCURSOR_PENCIL, _( "Add circle" ) );
1172  break;
1173 
1175  SetToolID( id, wxCURSOR_PENCIL, _( "Add arc" ) );
1176  break;
1177 
1179  SetToolID( id, wxCURSOR_PENCIL, _( "Add line" ) );
1180  break;
1181 
1183  SetToolID( id, wxCURSOR_HAND, _( "Set anchor position" ) );
1184  break;
1185 
1187  SetToolID( id, m_canvas->GetDefaultCursor(), _( "Import" ) );
1188  LoadOneSymbol();
1189  SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
1190  break;
1191 
1193  SetToolID( id, m_canvas->GetDefaultCursor(), _( "Export" ) );
1194  SaveOneSymbol();
1195  SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
1196  break;
1197 
1198  case ID_LIBEDIT_DELETE_ITEM_BUTT:
1199  if( !part )
1200  {
1201  wxBell();
1202  break;
1203  }
1204 
1205  SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
1206  break;
1207 
1208  default:
1209  break;
1210  }
1211 
1212  m_canvas->SetIgnoreMouseEvents( false );
1213 }
1214 
1215 
1216 void LIB_EDIT_FRAME::OnRotateItem( wxCommandEvent& aEvent )
1217 {
1218  if( m_drawItem == NULL )
1219  return;
1220 
1221  if( !m_drawItem->InEditMode() )
1222  {
1223  LIB_PART* part = GetCurPart();
1224 
1225  SaveCopyInUndoList( part );
1227  }
1228 
1229  m_drawItem->Rotate();
1230  OnModify();
1231 
1232  if( !m_drawItem->InEditMode() )
1234 
1235  m_canvas->Refresh();
1236 
1237  if( GetToolId() == ID_NO_TOOL_SELECTED )
1238  m_lastDrawItem = NULL;
1239 }
1240 
1241 
1242 void LIB_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent )
1243 {
1245  SCH_SCREEN* screen = GetScreen();
1246  // Allows block rotate operation on hot key.
1247  if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK )
1248  {
1249  if( aEvent.GetId() == ID_LIBEDIT_MIRROR_X )
1250  {
1252  screen->m_BlockLocate.SetMessageBlock( this );
1254  HandleBlockEnd( &dc );
1255  }
1256  else if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y )
1257  {
1259  screen->m_BlockLocate.SetMessageBlock( this );
1261  HandleBlockEnd( &dc );
1262  }
1263  }
1264 }
1265 
1266 
1268  const KICAD_T aFilterList[] )
1269 {
1270  LIB_PART* part = GetCurPart();
1271 
1272  if( !part )
1273  return NULL;
1274 
1275  LIB_ITEM* item = locateItem( aPosition, aFilterList );
1276 
1277  wxPoint pos = GetNearestGridPosition( aPosition );
1278 
1279  if( item == NULL && aPosition != pos )
1280  item = locateItem( pos, aFilterList );
1281 
1282  return item;
1283 }
1284 
1285 
1286 LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aFilterList[] )
1287 {
1288  LIB_PART* part = GetCurPart();
1289 
1290  if( !part )
1291  return NULL;
1292 
1293  LIB_ITEM* item = NULL;
1294 
1295  m_collectedItems.Collect( part->GetDrawItemList(), aFilterList, aPosition,
1296  m_unit, m_convert );
1297 
1298  if( m_collectedItems.GetCount() == 0 )
1299  {
1300  ClearMsgPanel();
1301  }
1302  else if( m_collectedItems.GetCount() == 1 )
1303  {
1304  item = m_collectedItems[0];
1305  }
1306  else
1307  {
1308  if( item == NULL )
1309  {
1310  wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS,
1311  "Select item clarification context menu size limit exceeded." );
1312 
1313  wxMenu selectMenu;
1314  AddMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ),
1315  KiBitmap( dismiss_xpm ) );
1316 
1317  selectMenu.AppendSeparator();
1318 
1319  for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ )
1320  {
1321  wxString text = m_collectedItems[i]->GetSelectMenuText();
1322  BITMAP_DEF xpm = m_collectedItems[i]->GetMenuImage();
1323 
1324  AddMenuItem( &selectMenu, ID_SELECT_ITEM_START + i, text, KiBitmap( xpm ) );
1325  }
1326 
1327  // Set to NULL in case user aborts the clarification context menu.
1328  m_drawItem = NULL;
1329  m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected
1330  PopupMenu( &selectMenu );
1332  item = m_drawItem;
1333  }
1334  }
1335 
1336  if( item )
1337  {
1338  MSG_PANEL_ITEMS items;
1339  item->GetMsgPanelInfo( items );
1340  SetMsgPanel( items );
1341  }
1342  else
1343  {
1344  ClearMsgPanel();
1345  }
1346 
1347  return item;
1348 }
1349 
1350 
1352 {
1353  wxCHECK_RET( m_drawItem != NULL, "No drawing item selected to delete." );
1354 
1355  m_canvas->CrossHairOff( aDC );
1356 
1357  LIB_PART* part = GetCurPart();
1358 
1359  SaveCopyInUndoList( part );
1360 
1361  if( m_drawItem->Type() == LIB_PIN_T )
1362  {
1363  LIB_PIN* pin = (LIB_PIN*) m_drawItem;
1364  wxPoint pos = pin->GetPosition();
1365 
1366  part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC );
1367 
1368  if( SynchronizePins() )
1369  {
1370  LIB_PIN* tmp = part->GetNextPin();
1371 
1372  while( tmp != NULL )
1373  {
1374  pin = tmp;
1375  tmp = part->GetNextPin( pin );
1376 
1377  if( pin->GetPosition() != pos )
1378  continue;
1379 
1380  part->RemoveDrawItem( (LIB_ITEM*) pin );
1381  }
1382  }
1383 
1384  m_canvas->Refresh();
1385  }
1386  else
1387  {
1388  if( m_canvas->IsMouseCaptured() )
1389  {
1390  m_canvas->CallEndMouseCapture( aDC );
1391  }
1392  else
1393  {
1394  part->RemoveDrawItem( m_drawItem, m_canvas, aDC );
1395  m_canvas->Refresh();
1396  }
1397  }
1398 
1399  m_drawItem = NULL;
1400  m_lastDrawItem = NULL;
1401  OnModify();
1402  m_canvas->CrossHairOn( aDC );
1403 }
1404 
1405 
1406 void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent )
1407 {
1408  int id = aEvent.GetId();
1409  int index = id - ID_SELECT_ITEM_START;
1410 
1411  if( (id >= ID_SELECT_ITEM_START && id <= ID_SELECT_ITEM_END)
1412  && (index >= 0 && index < m_collectedItems.GetCount()) )
1413  {
1414  LIB_ITEM* item = m_collectedItems[index];
1415  m_canvas->SetAbortRequest( false );
1416  m_drawItem = item;
1417  }
1418 }
1419 
1420 
1421 void LIB_EDIT_FRAME::OnOpenPinTable( wxCommandEvent& aEvent )
1422 {
1423  LIB_PART* part = GetCurPart();
1424 
1425  DIALOG_LIB_EDIT_PIN_TABLE dlg( this, *part );
1426 
1427  if( dlg.ShowModal() == wxID_CANCEL )
1428  return;
1429 
1430  return;
1431 }
1432 
1433 
1435 {
1436  LIB_PART* part = GetCurPart();
1437 
1438  return !m_editPinsPerPartOrConvert && ( part &&
1439  ( part->HasConversion() || part->IsMulti() ) );
1440 }
1441 
1442 
1444 {
1445  // This is not the most effecient way to do this because the changed library may not have
1446  // any effect on the schematic symbol links. Since this is not called very often, take the
1447  // hit here rather than the myriad other places (including SCH_SCREEN::Draw()) where it was
1448  // being called.
1449  SCH_SCREENS schematic;
1450 
1451  schematic.UpdateSymbolLinks();
1452  schematic.TestDanglingEnds();
1453 
1454  // There may be no parent window so use KIWAY message to refresh the schematic editor
1455  // in case any symbols have changed.
1456  Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_REFRESH, std::string( "" ), this );
1457 }
void OnViewEntryDoc(wxCommandEvent &event)
EDA_PANEINFO & HorizontalToolbarPane()
Function HorizontalToolbarPane Change *this to a horizontal toolbar for KiCad.
Definition: wxstruct.h:474
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
int GetCount() const
Function GetCount returns the number of objects in the list.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
#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
#define KICAD_DEFAULT_DRAWFRAME_STYLE
Definition: wxstruct.h:55
void OnUpdateEditingPart(wxUpdateUIEvent &event)
bool UnitsLocked() const
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:255
void SaveOneSymbol()
Function SaveOneSymbol saves the current component to a symbol file.
Definition: symbedit.cpp:142
const EDA_RECT GetUnitBoundingBox(int aUnit, int aConvert) const
Function GetBoundingBox.
static double m_current_text_angle
Current text angle setting.
Definition: libeditframe.h:112
Part library alias object definition.
bool IsMulti() const
Function IsMulti.
KICAD_MANAGER_FRAME::Process_Config KICAD_MANAGER_FRAME::OnUpdatePreferredPdfBrowser EVT_UPDATE_UI_RANGE(ID_TO_SCH, ID_TO_PCB_FP_EDITOR, KICAD_MANAGER_FRAME::OnUpdateRequiresProject) enum hotkey_id_commnand
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:327
LIB_ITEMS & GetDrawItemList()
Return a reference to the draw item list.
PNG memory record (file in memory).
Definition: bitmap_types.h:38
PART_LIB * GetCurLib()
The current library being edited, or NULL if none.
#define MAX_SELECT_ITEM_IDS
The maximum number of items in the clarify selection context menu.
Definition: eeschema_id.h:41
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
static int m_convert
Definition: libeditframe.h:99
bool m_showAxis
True shows the X and Y axis indicators.
Definition: draw_frame.h:102
void RestoreComponent()
Function 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
Definition: draw_panel.cpp:326
int ExportPartId
This file is part of the common library.
bool SaveActiveLibrary(bool newFile)
Function SaveActiveLibrary saves the changes to the current library.
Definition: libedit.cpp:302
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:299
static LIB_ITEM * m_drawItem
Definition: libeditframe.h:91
Class LIB_TEXT defines a component library graphical text item.
Definition: lib_text.h:45
void ClearTempCopyComponent()
Function ClearTempCopyComponent delete temporary copy of the current component and clear pointer...
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:55
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:140
void SetScrollCenterPosition(const wxPoint &aPoint)
Class LIB_FIELD is used in symbol libraries.
Definition: lib_field.h:60
virtual void OnActivate(wxActivateEvent &event) override
Function OnActivate is 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)
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.
int ImportPartId
void OnUpdateSaveCurrentLib(wxUpdateUIEvent &event)
int GetHeight() const
void GlobalSetPins(LIB_PIN *aMasterPin, int aId)
Function GlobalSetPins.
Definition: pinedit.cpp:560
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)
LIB_FIELD & GetValueField()
Return reference to the value field.
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
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
Definition: basicframe.cpp:361
void OnModify()
Function OnModify Must be called after a schematic change in order to set the "modify" flag of the cu...
Definition: libeditframe.h:369
bool IsModify() const
void OnSelectBodyStyle(wxCommandEvent &event)
void OnUpdateDeMorganNormal(wxUpdateUIEvent &event)
void LoadOneSymbol()
Function LoadOneSymbol read a component symbol file (*.sym ) and add graphic items to the current com...
Definition: symbedit.cpp:46
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:139
Class LIB_ID.
Definition: lib_id.h:56
size_t GetAliasCount() const
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
Definition: draw_panel.cpp:348
void OnUpdateDeMorganConvert(wxUpdateUIEvent &event)
void UpdateAliasSelectList()
void SelectActiveLibrary(PART_LIB *aLibrary=NULL)
Function SelectActiveLibrary sets the current active library to aLibrary.
Definition: libedit.cpp:66
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:53
Specialization of the wxAuiPaneInfo class for KiCad panels.
Definition: wxstruct.h:465
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
virtual bool HandleBlockEnd(wxDC *DC) override
Function HandleBlockEnd performs a block end command.
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:77
void SetShowDeMorgan(bool show)
Definition: libeditframe.h:405
EVT_MENU(ID_SELECT_PREFERED_PDF_BROWSER_NAME, KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser) EVT_MENU_RANGE(ID_PREFERENCES_HOTKEY_START
void OnOrient(wxCommandEvent &aEvent)
Function OnOrient Handles the ID_LIBEDIT_MIRROR_X and ID_LIBEDIT_MIRROR_Y events. ...
void DisplayLibInfos()
Function DisplayLibInfos updates the main window title bar with the current library name and read onl...
Definition: libedit.cpp:55
void OnEditComponentProperties(wxCommandEvent &event)
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 EVT_UPDATE_UI(ID_MODEDIT_CREATE_NEW_LIB_AND_SAVE_CURRENT_PART, FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected) EVT_UPDATE_UI(ID_MODEDIT_LOAD_MODULE_FROM_BOARD
BOX2I boundingBox(T aObject)
boundingBox template method
Definition: shape_index.h:59
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
EDA_PANEINFO & VerticalToolbarPane()
Function VerticalToolbarPane Change *this to a vertical toolbar for KiCad.
Definition: wxstruct.h:492
a helper to handle the real device context used in KiCad
wxAuiToolBar * m_optionsToolBar
The options tool bar typcially located on the left edge of the main window.
Definition: draw_frame.h:125
LIB_EDIT_FRAME(KIWAY *aKiway, wxWindow *aParent)
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
EDA_HOTKEY_CONFIG * m_hotkeysDescrList
Definition: draw_frame.h:76
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
void ReCreateMenuBar() override
(Re)Create the menubar for the component editor frame
void SetDrawItem(LIB_ITEM *drawItem)
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:754
LIB_COLLECTOR m_collectedItems
Used for hit testing.
Definition: libeditframe.h:55
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:128
void OnUpdateSelectAlias(wxUpdateUIEvent &event)
const wxString & GetName() const
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
void deleteItem(wxDC *aDC)
Function deleteItem deletes the currently selected draw item.
void OnUpdateViewDoc(wxUpdateUIEvent &event)
void OnUpdatePinTable(wxUpdateUIEvent &event)
void UpdateSymbolLinks()
wxComboBox * m_partSelectBox
a Box to select a part to edit (if any)
Definition: libeditframe.h:56
virtual void Rotate(const wxPoint &aCenter, bool aRotateCCW=true)=0
Function Rotate rotates the object about aCenter point.
LIB_ITEM * locateItem(const wxPoint &aPosition, const KICAD_T aFilterList[])
const wxString GetName() const
Return the file name without path or extension.
#define LIB_EDIT_FRAME_NAME
void TempCopyComponent()
Function TempCopyComponent create a temporary copy of the current edited component Used to prepare an...
Class LIB_PART defines a library part object.
unsigned STATUS_FLAGS
Definition: base_struct.h:144
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
static int m_textPinNumDefaultSize
The default pin num text size setting.
Definition: libeditframe.h:115
wxPoint m_FramePos
Definition: wxstruct.h:129
static LIB_ITEM * m_lastDrawItem
Definition: libeditframe.h:90
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:88
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:109
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:535
void OnSelectTool(wxCommandEvent &aEvent)
bool IsModified() const
void OnShowElectricalType(wxCommandEvent &event)
From Option toolbar: option to show the electrical pin type name.
int m_LastGridSizeId
Definition: draw_frame.h:77
bool SaveOnePart(PART_LIB *aLib, bool aPromptUser=true)
Function SaveOnePart saves the current LIB_PART into the provided PART_LIB.
Definition: libedit.cpp:697
void StartModifyDrawSymbol(wxDC *DC)
Definition: symbdraw.cpp:312
void CrossHairOff(wxDC *DC)
Definition: draw_panel.cpp:253
The the schematic editor to refresh the display.
Definition: mail_type.h:47
friend class DIALOG_LIB_EDIT_TEXT
Definition: libeditframe.h:128
wxAuiToolBar * m_drawToolBar
The tool bar that contains the buttons for quick access to the application draw tools.
Definition: draw_frame.h:122
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:135
void OnRotateItem(wxCommandEvent &aEvent)
Function OnRotateItem rotates the current item.
void Process_Special_Functions(wxCommandEvent &event)
void SetAbortRequest(bool aAbortRequest)
void CreateOptionToolbar()
Definition: tool_lib.cpp:224
EVT_TOOL_RANGE(ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_DELETE_ITEM_BUTT, LIB_EDIT_FRAME::OnSelectTool) EVT_MENU_RANGE(ID_PREFERENCES_HOTKEY_START
void DisplayCmpDoc()
Function DisplayCmpDoc displays the documentation of the selected component.
Definition: libedit.cpp:455
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:162
void SetShowElectricalType(bool aShow)
Definition: libeditframe.h:409
wxPoint GetPosition() const override
Function GetPosition returns the current draw object position.
Definition: lib_pin.h:471
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:118
void EditSymbolText(wxDC *DC, LIB_ITEM *DrawItem)
Class PART_LIBS is a collection of PART_LIBs.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
void OnSelectItem(wxCommandEvent &aEvent)
void OnOpenPinTable(wxCommandEvent &aEvent)
void SetUnit(int aUnit)
wxString GetDocFileName() const
#define GR_DEFAULT_DRAWMODE
Definition: general.h:70
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:177
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:511
int DisplayExitDialog(wxWindow *parent, const wxString &aMessage)
Function DisplayExitDialog displays a dialog with 3 buttons: Save and Exit Cancel Exit without save...
Definition: confirm.cpp:58
void CrossHairOn(wxDC *DC)
Definition: draw_panel.cpp:260
virtual void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo displays basic info (type, part and convert) about the current item in messa...
void OnSaveCurrentPart(wxCommandEvent &aEvent)
PART_LIB * SetCurLib(PART_LIB *aLib)
Sets the current library and return the old.
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Function GetNearestGridPosition returns the nearest aGridSize location to aPosition.
The component library editor main window.
Definition: libeditframe.h:51
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
see class PGM_BASE
TRANSFORM DefaultTransform
Definition: eeschema.cpp:57
void ReCreateHToolbar() override
Definition: tool_lib.cpp:102
void OnCreateNewPartFromExisting(wxCommandEvent &event)
static wxString m_aliasName
Definition: libeditframe.h:92
bool GetShowDeMorgan()
Definition: libeditframe.h:403
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:95
void TestDanglingEnds()
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)
Function SetCurPart takes ownership over 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:387
#define INSTALL_UNBUFFERED_DC(name, parent)
void OnUpdateNotEditingPart(wxUpdateUIEvent &event)
virtual void HandleBlockPlace(wxDC *DC) override
Function HandleBlockPlace handles the block place command.
int GetToolId() const
Definition: draw_frame.h:406
static FILL_T m_drawFillStyle
The current draw or edit graphic item fill style.
Definition: libeditframe.h:85
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
Definition: wxstruct.h:112
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
void EndDrawGraphicItem(wxDC *DC)
Definition: symbdraw.cpp:339
void SetIgnoreMouseEvents(bool aIgnore)
Class EDA_RECT handles the component boundary box.
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Function SubReference.
LIB_PART * GetCurPart()
Function GetCurPart returns the current part being edited, or NULL if none selected.
void Collect(LIB_ITEMS &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 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:121
void EditGraphicSymbol(wxDC *DC, LIB_ITEM *DrawItem)
Definition: symbdraw.cpp:58
int GetWidth() const
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
#define DEFAULTPINNAMESIZE
Definition: general.h:68
const char * name
void SetEnableBlockCommands(bool aEnable)
int m_repeatPinStep
Default repeat offset for pins in repeat place pin.
Definition: libeditframe.h:124
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:56
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
bool SynchronizePins()
Function SycnronizePins.
int CreateNewLibAndSavePartId
void OnUpdateElectricalType(wxUpdateUIEvent &aEvent)
bool IsEditingDrawItem()
Definition: libeditframe.h:439
const PAGE_INFO & GetPageSettings() const
LIB_EDIT_FRAME::Process_Config ID_POPUP_GENERAL_END_RANGE
void EditField(LIB_FIELD *Field)
Definition: libfield.cpp:39
bool IsReadOnly() const
Function IsReadOnly.
static int m_drawLineWidth
Default line width for drawing or editing graphic items.
Definition: libeditframe.h:88
bool m_drawSpecificConvert
Convert of the item currently being drawn.
Definition: libeditframe.h:60
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:130
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:106
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:68
Message panel definition file.
void OnSelectPart(wxCommandEvent &event)
int GetDefaultCursor() const
Function GetDefaultCursor return the default cursor shape.
Class SCH_BASE_FRAME is a shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRA...
Class PART_LIB is used to load, save, search, and otherwise manipulate part library files...
bool m_editPinsPerPartOrConvert
Set to true to not synchronize pins at the same position when editing components with multiple parts ...
Definition: libeditframe.h:77
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:111
void UpdatePartSelectList()
virtual void OnActivate(wxActivateEvent &event)
Function OnActivate (virtual) is called when activating the frame.
Definition: draw_frame.cpp:257
void StartMoveDrawSymbol(wxDC *DC)
Definition: symbdraw.cpp:291
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:745
static wxSize m_clientSize
Definition: libeditframe.h:126
Definition of class LIB_EDIT_FRAME.
Class SCH_SCREENS is a container class that holds multiple SCH_SCREENs in a hierarchy.
bool GetShowElectricalType()
Definition: libeditframe.h:407
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)
wxComboBox * m_aliasSelectBox
a box to select the alias to edit (if any)
Definition: libeditframe.h:57
LIB_PART * m_tempCopyComponent
temp copy of a part during edit, I own it here.
Definition: libeditframe.h:54
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy)
Function SaveCopyInUndoList.
void ReCreateVToolbar() override
Definition: tool_lib.cpp:53