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_VIEW_DOC, LIB_EDIT_FRAME::OnUpdateViewDoc )
170  EVT_UPDATE_UI( ID_LIBEDIT_EDIT_PIN_BY_PIN, LIB_EDIT_FRAME::OnUpdatePinByPin )
171  EVT_UPDATE_UI( ID_LIBEDIT_EDIT_PIN_BY_TABLE, LIB_EDIT_FRAME::OnUpdatePinTable )
172  EVT_UPDATE_UI( ID_LIBEDIT_SELECT_PART_NUMBER, LIB_EDIT_FRAME::OnUpdatePartNumber )
173  EVT_UPDATE_UI( ID_LIBEDIT_SELECT_ALIAS, LIB_EDIT_FRAME::OnUpdateSelectAlias )
174  EVT_UPDATE_UI( ID_DE_MORGAN_NORMAL_BUTT, LIB_EDIT_FRAME::OnUpdateDeMorganNormal )
175  EVT_UPDATE_UI( ID_DE_MORGAN_CONVERT_BUTT, LIB_EDIT_FRAME::OnUpdateDeMorganConvert )
176  EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, LIB_EDIT_FRAME::OnUpdateEditingPart )
177  EVT_UPDATE_UI( ID_ZOOM_SELECTION, LIB_EDIT_FRAME::OnUpdateEditingPart )
178  EVT_UPDATE_UI_RANGE( ID_LIBEDIT_PIN_BUTT, ID_LIBEDIT_DELETE_ITEM_BUTT,
179  LIB_EDIT_FRAME::OnUpdateEditingPart )
180  EVT_UPDATE_UI( ID_LIBEDIT_SHOW_ELECTRICAL_TYPE, LIB_EDIT_FRAME::OnUpdateElectricalType )
181 
182 END_EVENT_TABLE()
183 
184 #define LIB_EDIT_FRAME_NAME wxT( "LibeditFrame" )
185 
186 LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
187  SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_LIB_EDITOR, _( "Library Editor" ),
188  wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, LIB_EDIT_FRAME_NAME )
189 {
190  m_showAxis = true; // true to draw axis
191  SetShowDeMorgan( false );
192  m_drawSpecificConvert = true;
193  m_drawSpecificUnit = false;
197  SetShowElectricalType( true );
198 
199  m_my_part = NULL;
200  m_tempCopyComponent = NULL;
201 
202  // Delayed initialization
203  if( m_textSize == -1 )
205 
206  // Initialize grid id to the default value 50 mils:
208 
209  wxIcon icon;
210  icon.CopyFromBitmap( KiBitmap( icon_libedit_xpm ) );
211  SetIcon( icon );
212 
213  LoadSettings( config() );
214 
215  SetScreen( new SCH_SCREEN( aKiway ) );
216  GetScreen()->m_Center = true;
218 
219  SetCrossHairPosition( wxPoint( 0, 0 ) );
220 
221  // Ensure m_LastGridSizeId is an offset inside the allowed schematic range
222  if( m_LastGridSizeId < ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000 )
224 
225  if( m_LastGridSizeId > ID_POPUP_GRID_LEVEL_1 - ID_POPUP_GRID_LEVEL_1000 )
227 
228  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
229 
230  GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
231 
232  if( m_canvas )
234 
235  ReCreateMenuBar();
238 
239  // Ensure the current alias name is valid if a part is loaded
240  // Sometimes it is not valid. This is the case
241  // when a part value (the part lib name), or the alias list was modified
242  // during a previous session and the modifications not saved in lib.
243  // Reopen libedit in a new session gives a non valid m_aliasName
244  // because the curr part is reloaded from the library (and this is the unmodified part)
245  // and the old alias name (from the previous edition) can be invalid
246  LIB_PART* part = GetCurPart();
247 
248  if( part == NULL )
249  m_aliasName.Empty();
250  else if( m_aliasName != part->GetName() )
251  {
252  LIB_ALIAS* alias = part->GetAlias( m_aliasName );
253 
254  if( !alias )
255  m_aliasName = part->GetName();
256  }
257 
258 
260  DisplayLibInfos();
261  DisplayCmpDoc();
264 
265  m_auimgr.SetManagedWindow( this );
266 
267  EDA_PANEINFO horiz;
268  horiz.HorizontalToolbarPane();
269 
270  EDA_PANEINFO vert;
271  vert.VerticalToolbarPane();
272 
273  EDA_PANEINFO mesg;
274  mesg.MessageToolbarPane();
275 
276  m_auimgr.AddPane( m_mainToolBar,
277  wxAuiPaneInfo( horiz ).Name( "m_mainToolBar" ).Top().Row( 0 ) );
278 
279  m_auimgr.AddPane( m_drawToolBar,
280  wxAuiPaneInfo( vert ).Name( "m_VToolBar" ).Right() );
281 
282  m_auimgr.AddPane( m_optionsToolBar,
283  wxAuiPaneInfo( vert ).Name( "m_optionsToolBar" ).Left() );
284 
285  m_auimgr.AddPane( m_canvas,
286  wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
287 
288  m_auimgr.AddPane( m_messagePanel,
289  wxAuiPaneInfo( mesg ).Name( "MsgPanel" ).Bottom().Layer(10) );
290 
291  m_auimgr.Update();
292 
293  Raise();
294  Show( true );
295 
296  wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, ID_ZOOM_PAGE );
297  wxPostEvent( this, evt );
298 }
299 
300 
302 {
303  m_drawItem = m_lastDrawItem = NULL;
304 
305  delete m_tempCopyComponent;
306  delete m_my_part;
307  m_my_part = NULL;
308  m_tempCopyComponent = NULL;
309 }
310 
311 
313 {
314  m_drawItem = drawItem;
315 }
316 
317 
318 void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
319 {
320  if( GetScreen()->IsModify() )
321  {
322  int ii = DisplayExitDialog( this, _( "Save the changes in the library before closing?" ) );
323 
324  switch( ii )
325  {
326  case wxID_NO:
327  break;
328 
329  case wxID_YES:
330  if ( this->SaveActiveLibrary( false ) )
331  break;
332 
333  // fall through: cancel the close because of an error
334 
335  case wxID_CANCEL:
336  Event.Veto();
337  return;
338  }
339  GetScreen()->ClrModify();
340  }
341 
342  PART_LIBS* libs = Prj().SchLibs();
343 
344  for( const PART_LIB& lib : *libs )
345  {
346  if( lib.IsModified() )
347  {
348  wxString msg = wxString::Format( _(
349  "Library '%s' was modified!\nDiscard changes?" ),
350  GetChars( lib.GetName() )
351  );
352 
353  if( !IsOK( this, msg ) )
354  {
355  Event.Veto();
356  return;
357  }
358  }
359  }
360 
361  Destroy();
362 }
363 
364 
366 {
367  /* Please, note: wxMSW before version 2.9 seems have
368  * problems with zoom values < 1 ( i.e. userscale > 1) and needs to be patched:
369  * edit file <wxWidgets>/src/msw/dc.cpp
370  * search for line static const int VIEWPORT_EXTENT = 1000;
371  * and replace by static const int VIEWPORT_EXTENT = 10000;
372  */
373  int dx, dy;
374 
375  LIB_PART* part = GetCurPart();
376 
377  if( part )
378  {
380 
381  dx = boundingBox.GetWidth();
382  dy = boundingBox.GetHeight();
383  SetScrollCenterPosition( wxPoint( 0, 0 ) );
384  }
385  else
386  {
387  const PAGE_INFO& pageInfo = GetScreen()->GetPageSettings();
388 
389  dx = pageInfo.GetSizeIU().x;
390  dy = pageInfo.GetSizeIU().y;
391 
392  SetScrollCenterPosition( wxPoint( 0, 0 ) );
393  }
394 
395  wxSize size = m_canvas->GetClientSize();
396 
397  // Reserve a 10% margin around component bounding box.
398  double margin_scale_factor = 0.8;
399  double zx =(double) dx / ( margin_scale_factor * (double)size.x );
400  double zy = (double) dy / ( margin_scale_factor * (double)size.y );
401 
402  double bestzoom = std::max( zx, zy );
403 
404  // keep it >= minimal existing zoom (can happen for very small components
405  // for instance when starting a new component
406  if( bestzoom < GetScreen()->m_ZoomList[0] )
407  bestzoom = GetScreen()->m_ZoomList[0];
408 
409  return bestzoom;
410 }
411 
412 
414 {
415  if( m_aliasSelectBox == NULL )
416  return;
417 
418  m_aliasSelectBox->Clear();
419 
420  LIB_PART* part = GetCurPart();
421 
422  if( !part )
423  return;
424 
425  m_aliasSelectBox->Append( part->GetAliasNames() );
426  m_aliasSelectBox->SetSelection( 0 );
427 
428  int index = m_aliasSelectBox->FindString( m_aliasName );
429 
430  if( index != wxNOT_FOUND )
431  m_aliasSelectBox->SetSelection( index );
432 }
433 
434 
436 {
437  if( m_partSelectBox == NULL )
438  return;
439 
440  if( m_partSelectBox->GetCount() != 0 )
441  m_partSelectBox->Clear();
442 
443  LIB_PART* part = GetCurPart();
444 
445  if( !part || part->GetUnitCount() <= 1 )
446  {
447  m_unit = 1;
448  m_partSelectBox->Append( wxEmptyString );
449  }
450  else
451  {
452  for( int i = 0; i < part->GetUnitCount(); i++ )
453  {
454  wxString sub = LIB_PART::SubReference( i+1, false );
455  wxString unit = wxString::Format( _( "Unit %s" ), GetChars( sub ) );
456  m_partSelectBox->Append( unit );
457  }
458  }
459 
460  // Ensure the current selected unit is compatible with
461  // the number of units of the current part:
462  if( part && part->GetUnitCount() < m_unit )
463  m_unit = 1;
464 
465  m_partSelectBox->SetSelection( ( m_unit > 0 ) ? m_unit - 1 : 0 );
466 }
467 
468 
469 void LIB_EDIT_FRAME::OnShowElectricalType( wxCommandEvent& event )
470 {
472  GetCanvas()->Refresh();
473 }
474 
475 
476 void LIB_EDIT_FRAME::OnUpdateElectricalType( wxUpdateUIEvent& aEvent )
477 {
478  aEvent.Check( GetShowElectricalType() );
479 }
480 
481 
482 void LIB_EDIT_FRAME::OnUpdateEditingPart( wxUpdateUIEvent& aEvent )
483 {
484  LIB_PART* part = GetCurPart();
485 
486  aEvent.Enable( part != NULL );
487 
488  if( part && aEvent.GetEventObject() == m_drawToolBar )
489  aEvent.Check( GetToolId() == aEvent.GetId() );
490 }
491 
492 
493 void LIB_EDIT_FRAME::OnUpdateNotEditingPart( wxUpdateUIEvent& event )
494 {
495  event.Enable( !GetCurPart() );
496 }
497 
498 
499 void LIB_EDIT_FRAME::OnUpdateUndo( wxUpdateUIEvent& event )
500 {
501  event.Enable( GetCurPart() && GetScreen() &&
502  GetScreen()->GetUndoCommandCount() != 0 && !IsEditingDrawItem() );
503 }
504 
505 
506 void LIB_EDIT_FRAME::OnUpdateRedo( wxUpdateUIEvent& event )
507 {
508  event.Enable( GetCurPart() && GetScreen() &&
509  GetScreen()->GetRedoCommandCount() != 0 && !IsEditingDrawItem() );
510 }
511 
512 
513 void LIB_EDIT_FRAME::OnUpdateSaveCurrentLib( wxUpdateUIEvent& event )
514 {
515  PART_LIB* lib = GetCurLib();
516 
517  event.Enable( lib && !lib->IsReadOnly()
518  && ( lib->IsModified() || GetScreen()->IsModify() ) );
519 }
520 
521 
522 void LIB_EDIT_FRAME::OnUpdateViewDoc( wxUpdateUIEvent& event )
523 {
524  bool enable = false;
525 
526  PART_LIB* lib = GetCurLib();
527  LIB_PART* part = GetCurPart();
528 
529  if( part && lib )
530  {
531  LIB_ALIAS* alias = part->GetAlias( m_aliasName );
532 
533  wxCHECK_RET( alias != NULL, wxT( "Alias <" ) + m_aliasName + wxT( "> not found." ) );
534 
535  enable = !alias->GetDocFileName().IsEmpty();
536  }
537 
538  event.Enable( enable );
539 }
540 
541 
542 void LIB_EDIT_FRAME::OnUpdatePinByPin( wxUpdateUIEvent& event )
543 {
544  LIB_PART* part = GetCurPart();
545 
546  event.Enable( part && ( part->GetUnitCount() > 1 || m_showDeMorgan ) );
547 
548  event.Check( m_editPinsPerPartOrConvert );
549 }
550 
551 
552 void LIB_EDIT_FRAME::OnUpdatePinTable( wxUpdateUIEvent& event )
553 {
554  LIB_PART* part = GetCurPart();
555  event.Enable( part != NULL );
556 }
557 
558 
559 void LIB_EDIT_FRAME::OnUpdatePartNumber( wxUpdateUIEvent& event )
560 {
561  if( m_partSelectBox == NULL )
562  return;
563 
564  LIB_PART* part = GetCurPart();
565 
566  // Using the typical event.Enable() call doesn't seem to work with wxGTK
567  // so use the pointer to alias combobox to directly enable or disable.
568  m_partSelectBox->Enable( part && part->GetUnitCount() > 1 );
569 }
570 
571 
572 void LIB_EDIT_FRAME::OnUpdateDeMorganNormal( wxUpdateUIEvent& event )
573 {
574  if( m_mainToolBar == NULL )
575  return;
576 
577  LIB_PART* part = GetCurPart();
578 
579  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
580  event.Check( m_convert <= 1 );
581 }
582 
583 
584 void LIB_EDIT_FRAME::OnUpdateDeMorganConvert( wxUpdateUIEvent& event )
585 {
586  if( m_mainToolBar == NULL )
587  return;
588 
589  LIB_PART* part = GetCurPart();
590 
591  event.Enable( GetShowDeMorgan() || ( part && part->HasConversion() ) );
592  event.Check( m_convert > 1 );
593 }
594 
595 
596 void LIB_EDIT_FRAME::OnUpdateSelectAlias( wxUpdateUIEvent& event )
597 {
598  if( m_aliasSelectBox == NULL )
599  return;
600 
601  LIB_PART* part = GetCurPart();
602 
603  // Using the typical event.Enable() call doesn't seem to work with wxGTK
604  // so use the pointer to alias combobox to directly enable or disable.
605  m_aliasSelectBox->Enable( part && part->GetAliasCount() > 1 );
606 }
607 
608 
609 void LIB_EDIT_FRAME::OnSelectAlias( wxCommandEvent& event )
610 {
611  if( m_aliasSelectBox == NULL
612  || ( m_aliasSelectBox->GetStringSelection().CmpNoCase( m_aliasName ) == 0) )
613  return;
614 
615  m_lastDrawItem = NULL;
616  m_aliasName = m_aliasSelectBox->GetStringSelection();
617 
618  DisplayCmpDoc();
619  m_canvas->Refresh();
620 }
621 
622 
623 void LIB_EDIT_FRAME::OnSelectPart( wxCommandEvent& event )
624 {
625  int i = event.GetSelection();
626 
627  if( ( i == wxNOT_FOUND ) || ( ( i + 1 ) == m_unit ) )
628  return;
629 
630  m_lastDrawItem = NULL;
631  m_unit = i + 1;
632  m_canvas->Refresh();
633  DisplayCmpDoc();
634 }
635 
636 
637 void LIB_EDIT_FRAME::OnViewEntryDoc( wxCommandEvent& event )
638 {
639  LIB_PART* part = GetCurPart();
640 
641  if( !part )
642  return;
643 
644  wxString fileName;
645  LIB_ALIAS* alias = part->GetAlias( m_aliasName );
646 
647  wxCHECK_RET( alias != NULL, "Alias not found." );
648 
649  fileName = alias->GetDocFileName();
650 
651  if( !fileName.IsEmpty() )
652  {
653  SEARCH_STACK* lib_search = Prj().SchSearchS();
654 
655  GetAssociatedDocument( this, fileName, lib_search );
656  }
657 }
658 
659 
660 void LIB_EDIT_FRAME::OnSelectBodyStyle( wxCommandEvent& event )
661 {
662  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
663 
664  if( event.GetId() == ID_DE_MORGAN_NORMAL_BUTT )
665  m_convert = 1;
666  else
667  m_convert = 2;
668 
669  m_lastDrawItem = NULL;
670  m_canvas->Refresh();
671 }
672 
673 
674 void LIB_EDIT_FRAME::OnSaveCurrentPart( wxCommandEvent& aEvent )
675 {
676  LIB_PART* part = GetCurPart();
677 
678  if( !part )
679  {
680  DisplayError( this, _( "No part to save." ) );
681  return;
682  }
683 
684  PART_LIB* lib = GetCurLib();
685 
686  if( !lib )
688 
689  lib = GetCurLib();
690 
691  if( !lib )
692  {
693  DisplayError( this, _( "No library specified." ) );
694  return;
695  }
696 
697  try
698  {
699  SaveOnePart( lib );
700  }
701  catch( ... )
702  {
703  wxString msg;
704  msg.Printf( _( "Unexpected error occured saving symbol '%s' to symbol library '%s'." ),
705  part->GetName(), lib->GetName() );
706  DisplayError( this, msg );
707  return;
708  }
709 
711 }
712 
713 
714 void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
715 {
716  int id = event.GetId();
717  wxPoint pos;
718 
720 
721  wxGetMousePosition( &pos.x, &pos.y );
722  pos.y += 20;
723 
724  switch( id ) // Stop placement commands before handling new command.
725  {
727  case ID_LIBEDIT_EDIT_PIN:
733  case ID_POPUP_ZOOM_BLOCK:
735  case ID_POPUP_COPY_BLOCK:
741  case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT:
742  break;
743 
745  if( m_canvas->IsMouseCaptured() )
747  else
748  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
749  break;
750 
753  break;
754 
755  default:
756  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(),
757  wxEmptyString );
758  break;
759  }
760 
762 
763  switch( id )
764  {
766  break;
767 
768  case ID_LIBEDIT_SELECT_CURRENT_LIB:
770  break;
771 
772  case ID_LIBEDIT_EDIT_PIN_BY_PIN:
773  m_editPinsPerPartOrConvert = m_mainToolBar->GetToolToggled( ID_LIBEDIT_EDIT_PIN_BY_PIN );
774  break;
775 
778  if( m_drawItem )
779  {
780  EndDrawGraphicItem( &dc );
781  }
782  break;
783 
785  if( m_drawItem )
786  {
787  m_canvas->CrossHairOff( &dc );
788 
789  switch( m_drawItem->Type() )
790  {
791  case LIB_ARC_T:
792  case LIB_CIRCLE_T:
793  case LIB_RECTANGLE_T:
794  case LIB_POLYLINE_T:
796  break;
797 
798  case LIB_TEXT_T:
799  EditSymbolText( &dc, m_drawItem );
800  break;
801 
802  default:
803  ;
804  }
805 
806  m_canvas->CrossHairOn( &dc );
807  }
808  break;
809 
810  case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT:
811  {
812  // Delete the last created segment, while creating a polyline draw item
813  if( m_drawItem == NULL )
814  break;
815 
817  STATUS_FLAGS oldFlags = m_drawItem->GetFlags();
819  m_drawItem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
821  ( (LIB_POLYLINE*) m_drawItem )->DeleteSegment( GetCrossHairPosition( true ) );
822  m_drawItem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
824  m_drawItem->SetFlags( oldFlags );
825  m_lastDrawItem = NULL;
826  }
827  break;
828 
830  if( m_drawItem )
831  deleteItem( &dc );
832 
833  break;
834 
836  if( m_drawItem == NULL )
837  break;
838 
839  if( m_drawItem->Type() == LIB_PIN_T )
840  StartMovePin( &dc );
841  else
842  StartMoveDrawSymbol( &dc );
843  break;
844 
846 
847  if( m_drawItem == NULL )
848  break;
849 
852  || m_drawItem->Type() == LIB_CIRCLE_T
854  || m_drawItem->Type() == LIB_ARC_T
855  )
856  {
857  StartModifyDrawSymbol( &dc );
858  }
859 
860  break;
861 
863  if( m_drawItem == NULL )
864  break;
865 
866  m_canvas->CrossHairOff( &dc );
867 
868  if( m_drawItem->Type() == LIB_FIELD_T )
869  {
871  }
872 
874  m_canvas->CrossHairOn( &dc );
875  break;
876 
880  {
881  if( !m_drawItem || m_drawItem->Type() != LIB_PIN_T )
882  break;
883 
884  LIB_PART* part = GetCurPart();
885 
886  SaveCopyInUndoList( part );
887 
888  GlobalSetPins( (LIB_PIN*) m_drawItem, id );
890  m_canvas->Refresh();
891  }
892  break;
893 
894  case ID_POPUP_ZOOM_BLOCK:
895  m_canvas->SetAutoPanRequest( false );
897  HandleBlockEnd( &dc );
898  break;
899 
901  m_canvas->SetAutoPanRequest( false );
904  HandleBlockEnd( &dc );
905  break;
906 
907  case ID_POPUP_COPY_BLOCK:
908  m_canvas->SetAutoPanRequest( false );
911  HandleBlockEnd( &dc );
912  break;
913 
915  m_canvas->SetAutoPanRequest( false );
918  HandleBlockEnd( &dc );
919  break;
920 
922  m_canvas->SetAutoPanRequest( false );
925  HandleBlockPlace( &dc );
926  break;
927 
929  m_canvas->SetAutoPanRequest( false );
932  HandleBlockPlace( &dc );
933  break;
934 
936  m_canvas->SetAutoPanRequest( false );
939  HandleBlockPlace( &dc );
940  break;
941 
943  m_canvas->SetAutoPanRequest( false );
945  HandleBlockPlace( &dc );
946  break;
947 
948  default:
949  DisplayError( this, "LIB_EDIT_FRAME::Process_Special_Functions error" );
950  break;
951  }
952 
953  m_canvas->SetIgnoreMouseEvents( false );
954 
955  if( GetToolId() == ID_NO_TOOL_SELECTED )
956  m_lastDrawItem = NULL;
957 }
958 
959 
960 void LIB_EDIT_FRAME::OnActivate( wxActivateEvent& event )
961 {
963 }
964 
965 
967 {
968  wxString name = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_LIB );
969 
970  if( !!name )
971  {
972  PART_LIB* lib = Prj().SchLibs()->FindLibrary( name );
973 
974  if( !lib )
975  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
976 
977  return lib;
978  }
979 
980  return NULL;
981 }
982 
983 
985 {
986  PART_LIB* old = GetCurLib();
987 
988  if( !aLib || !aLib->GetName() )
989  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
990  else
992 
993  return old;
994 }
995 
996 
998 {
999  if( !m_my_part )
1000  {
1001  wxString name = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_PART );
1002  LIB_PART* part;
1003 
1004  if( !!name && ( part = Prj().SchLibs()->FindLibPart( LIB_ID( wxEmptyString, name ) ) ) )
1005  {
1006  // clone it from the PART_LIB and own it.
1007  m_my_part = new LIB_PART( *part );
1008  }
1009  else
1010  Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_PART, wxEmptyString );
1011  }
1012 
1013  return m_my_part;
1014 }
1015 
1016 
1018 {
1019  delete m_my_part;
1020  m_my_part = aPart; // take ownership here
1021 
1022  // retain in case this wxFrame is re-opened later on the same PROJECT
1024  aPart ? aPart->GetName() : wxString() );
1025 }
1026 
1027 
1029 {
1030  delete m_tempCopyComponent;
1031 
1032  if( LIB_PART* part = GetCurPart() )
1033  // clone it and own the clone.
1034  m_tempCopyComponent = new LIB_PART( *part );
1035  else
1036  // clear it, there was no CurPart
1037  m_tempCopyComponent = NULL;
1038 }
1039 
1040 
1042 {
1043  if( m_tempCopyComponent )
1044  {
1045  // transfer ownership to CurPart
1047  m_tempCopyComponent = NULL;
1048  }
1049 }
1050 
1051 
1053 {
1054  delete m_tempCopyComponent;
1055  m_tempCopyComponent = NULL;
1056 }
1057 
1058 
1059 void LIB_EDIT_FRAME::EditSymbolText( wxDC* DC, LIB_ITEM* DrawItem )
1060 {
1061  if ( ( DrawItem == NULL ) || ( DrawItem->Type() != LIB_TEXT_T ) )
1062  return;
1063 
1064  // Deleting old text
1065  if( DC && !DrawItem->InEditMode() )
1066  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
1067  DefaultTransform );
1068 
1069  DIALOG_LIB_EDIT_TEXT* frame = new DIALOG_LIB_EDIT_TEXT( this, (LIB_TEXT*) DrawItem );
1070  frame->ShowModal();
1071  frame->Destroy();
1072  OnModify();
1073 
1074  // Display new text
1075  if( DC && !DrawItem->InEditMode() )
1076  DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, GR_DEFAULT_DRAWMODE,
1077  NULL, DefaultTransform );
1078 }
1079 
1080 
1081 void LIB_EDIT_FRAME::OnEditComponentProperties( wxCommandEvent& event )
1082 {
1083  bool partLocked = GetCurPart()->UnitsLocked();
1084 
1086 
1087  if( dlg.ShowModal() == wxID_CANCEL )
1088  return;
1089 
1090  if( partLocked != GetCurPart()->UnitsLocked() )
1091  {
1092  // m_editPinsPerPartOrConvert is set to the better value, if m_UnitSelectionLocked
1093  // has changed
1094  m_editPinsPerPartOrConvert = GetCurPart()->UnitsLocked() ? true : false;
1095  }
1096 
1099  DisplayLibInfos();
1100  DisplayCmpDoc();
1101  OnModify();
1102  m_canvas->Refresh();
1103 }
1104 
1105 
1106 void LIB_EDIT_FRAME::OnCreateNewPartFromExisting( wxCommandEvent& event )
1107 {
1108  LIB_PART* part = GetCurPart();
1109 
1110  wxCHECK_RET( part, "Cannot create new part from non-existent current part." );
1111 
1113  m_canvas->CrossHairOff( &dc );
1114 
1115  EditField( &part->GetValueField() );
1116 
1118  m_canvas->CrossHairOn( &dc );
1119 }
1120 
1121 
1122 void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
1123 {
1124  int id = aEvent.GetId();
1125 
1126  if( GetToolId() == ID_NO_TOOL_SELECTED )
1127  m_lastDrawItem = NULL;
1128 
1129  m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(),
1130  wxEmptyString );
1131 
1132  LIB_PART* part = GetCurPart();
1133 
1134  switch( id )
1135  {
1136  case ID_NO_TOOL_SELECTED:
1137  SetToolID( id, m_canvas->GetDefaultCursor(), wxEmptyString );
1138  break;
1139 
1140  case ID_ZOOM_SELECTION:
1141  SetToolID( id, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) );
1142  break;
1143 
1144  case ID_LIBEDIT_PIN_BUTT:
1145  if( part )
1146  {
1147  SetToolID( id, wxCURSOR_PENCIL, _( "Add pin" ) );
1148  }
1149  else
1150  {
1151  SetToolID( id, wxCURSOR_ARROW, _( "Set pin options" ) );
1152 
1153  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
1154 
1155  cmd.SetId( ID_LIBEDIT_EDIT_PIN );
1156  GetEventHandler()->ProcessEvent( cmd );
1157  SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
1158  }
1159  break;
1160 
1162  SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) );
1163  break;
1164 
1166  SetToolID( id, wxCURSOR_PENCIL, _( "Add rectangle" ) );
1167  break;
1168 
1170  SetToolID( id, wxCURSOR_PENCIL, _( "Add circle" ) );
1171  break;
1172 
1174  SetToolID( id, wxCURSOR_PENCIL, _( "Add arc" ) );
1175  break;
1176 
1178  SetToolID( id, wxCURSOR_PENCIL, _( "Add line" ) );
1179  break;
1180 
1182  SetToolID( id, wxCURSOR_HAND, _( "Set anchor position" ) );
1183  break;
1184 
1186  SetToolID( id, m_canvas->GetDefaultCursor(), _( "Import" ) );
1187  LoadOneSymbol();
1188  SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
1189  break;
1190 
1192  SetToolID( id, m_canvas->GetDefaultCursor(), _( "Export" ) );
1193  SaveOneSymbol();
1194  SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
1195  break;
1196 
1197  case ID_LIBEDIT_DELETE_ITEM_BUTT:
1198  if( !part )
1199  {
1200  wxBell();
1201  break;
1202  }
1203 
1204  SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
1205  break;
1206 
1207  default:
1208  break;
1209  }
1210 
1211  m_canvas->SetIgnoreMouseEvents( false );
1212 }
1213 
1214 
1215 void LIB_EDIT_FRAME::OnRotateItem( wxCommandEvent& aEvent )
1216 {
1217  if( m_drawItem == NULL )
1218  return;
1219 
1220  if( !m_drawItem->InEditMode() )
1221  {
1222  LIB_PART* part = GetCurPart();
1223 
1224  SaveCopyInUndoList( part );
1226  }
1227 
1228  m_drawItem->Rotate();
1229  OnModify();
1230 
1231  if( !m_drawItem->InEditMode() )
1233 
1234  m_canvas->Refresh();
1235 
1236  if( GetToolId() == ID_NO_TOOL_SELECTED )
1237  m_lastDrawItem = NULL;
1238 }
1239 
1240 
1241 void LIB_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent )
1242 {
1244  SCH_SCREEN* screen = GetScreen();
1245  // Allows block rotate operation on hot key.
1246  if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK )
1247  {
1248  if( aEvent.GetId() == ID_LIBEDIT_MIRROR_X )
1249  {
1251  screen->m_BlockLocate.SetMessageBlock( this );
1253  HandleBlockEnd( &dc );
1254  }
1255  else if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y )
1256  {
1258  screen->m_BlockLocate.SetMessageBlock( this );
1260  HandleBlockEnd( &dc );
1261  }
1262  }
1263 }
1264 
1265 
1267  const KICAD_T aFilterList[] )
1268 {
1269  LIB_PART* part = GetCurPart();
1270 
1271  if( !part )
1272  return NULL;
1273 
1274  LIB_ITEM* item = locateItem( aPosition, aFilterList );
1275 
1276  wxPoint pos = GetNearestGridPosition( aPosition );
1277 
1278  if( item == NULL && aPosition != pos )
1279  item = locateItem( pos, aFilterList );
1280 
1281  return item;
1282 }
1283 
1284 
1285 LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aFilterList[] )
1286 {
1287  LIB_PART* part = GetCurPart();
1288 
1289  if( !part )
1290  return NULL;
1291 
1292  LIB_ITEM* item = NULL;
1293 
1294  m_collectedItems.Collect( part->GetDrawItemList(), aFilterList, aPosition,
1295  m_unit, m_convert );
1296 
1297  if( m_collectedItems.GetCount() == 0 )
1298  {
1299  ClearMsgPanel();
1300  }
1301  else if( m_collectedItems.GetCount() == 1 )
1302  {
1303  item = m_collectedItems[0];
1304  }
1305  else
1306  {
1307  if( item == NULL )
1308  {
1309  wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS,
1310  "Select item clarification context menu size limit exceeded." );
1311 
1312  wxMenu selectMenu;
1313  AddMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ),
1314  KiBitmap( dismiss_xpm ) );
1315 
1316  selectMenu.AppendSeparator();
1317 
1318  for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ )
1319  {
1320  wxString text = m_collectedItems[i]->GetSelectMenuText();
1321  BITMAP_DEF xpm = m_collectedItems[i]->GetMenuImage();
1322 
1323  AddMenuItem( &selectMenu, ID_SELECT_ITEM_START + i, text, KiBitmap( xpm ) );
1324  }
1325 
1326  // Set to NULL in case user aborts the clarification context menu.
1327  m_drawItem = NULL;
1328  m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected
1329  PopupMenu( &selectMenu );
1331  item = m_drawItem;
1332  }
1333  }
1334 
1335  if( item )
1336  {
1337  MSG_PANEL_ITEMS items;
1338  item->GetMsgPanelInfo( items );
1339  SetMsgPanel( items );
1340  }
1341  else
1342  {
1343  ClearMsgPanel();
1344  }
1345 
1346  return item;
1347 }
1348 
1349 
1351 {
1352  wxCHECK_RET( m_drawItem != NULL, "No drawing item selected to delete." );
1353 
1354  m_canvas->CrossHairOff( aDC );
1355 
1356  LIB_PART* part = GetCurPart();
1357 
1358  SaveCopyInUndoList( part );
1359 
1360  if( m_drawItem->Type() == LIB_PIN_T )
1361  {
1362  LIB_PIN* pin = (LIB_PIN*) m_drawItem;
1363  wxPoint pos = pin->GetPosition();
1364 
1365  part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC );
1366 
1367  if( SynchronizePins() )
1368  {
1369  LIB_PIN* tmp = part->GetNextPin();
1370 
1371  while( tmp != NULL )
1372  {
1373  pin = tmp;
1374  tmp = part->GetNextPin( pin );
1375 
1376  if( pin->GetPosition() != pos )
1377  continue;
1378 
1379  part->RemoveDrawItem( (LIB_ITEM*) pin );
1380  }
1381  }
1382 
1383  m_canvas->Refresh();
1384  }
1385  else
1386  {
1387  if( m_canvas->IsMouseCaptured() )
1388  {
1389  m_canvas->CallEndMouseCapture( aDC );
1390  }
1391  else
1392  {
1393  part->RemoveDrawItem( m_drawItem, m_canvas, aDC );
1394  m_canvas->Refresh();
1395  }
1396  }
1397 
1398  m_drawItem = NULL;
1399  m_lastDrawItem = NULL;
1400  OnModify();
1401  m_canvas->CrossHairOn( aDC );
1402 }
1403 
1404 
1405 void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent )
1406 {
1407  int id = aEvent.GetId();
1408  int index = id - ID_SELECT_ITEM_START;
1409 
1410  if( (id >= ID_SELECT_ITEM_START && id <= ID_SELECT_ITEM_END)
1411  && (index >= 0 && index < m_collectedItems.GetCount()) )
1412  {
1413  LIB_ITEM* item = m_collectedItems[index];
1414  m_canvas->SetAbortRequest( false );
1415  m_drawItem = item;
1416  }
1417 }
1418 
1419 
1420 void LIB_EDIT_FRAME::OnOpenPinTable( wxCommandEvent& aEvent )
1421 {
1422  LIB_PART* part = GetCurPart();
1423 
1424  DIALOG_LIB_EDIT_PIN_TABLE dlg( this, *part );
1425 
1426  if( dlg.ShowModal() == wxID_CANCEL )
1427  return;
1428 
1429  return;
1430 }
1431 
1432 
1434 {
1435  LIB_PART* part = GetCurPart();
1436 
1437  return !m_editPinsPerPartOrConvert && ( part &&
1438  ( part->HasConversion() || part->IsMulti() ) );
1439 }
1440 
1441 
1443 {
1444  // This is not the most effecient way to do this because the changed library may not have
1445  // any effect on the schematic symbol links. Since this is not called very often, take the
1446  // hit here rather than the myriad other places (including SCH_SCREEN::Draw()) where it was
1447  // being called.
1448  SCH_SCREENS schematic;
1449 
1450  schematic.UpdateSymbolLinks();
1451  schematic.TestDanglingEnds();
1452 
1453  // There may be no parent window so use KIWAY message to refresh the schematic editor
1454  // in case any symbols have changed.
1455  Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_REFRESH, std::string( "" ), this );
1456 }
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:61
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:301
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:49
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:751
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:696
void StartModifyDrawSymbol(wxDC *DC)
Definition: symbdraw.cpp:304
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:454
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:69
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:331
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:67
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:64
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:283
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:742
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