KiCad PCB EDA Suite
libedit.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
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 <kiway.h>
33 #include <gr_basic.h>
34 #include <macros.h>
35 #include <pgm_base.h>
36 #include <class_drawpanel.h>
37 #include <confirm.h>
38 #include <gestfich.h>
39 #include <class_sch_screen.h>
40 
41 #include <eeschema_id.h>
42 #include <general.h>
43 #include <libeditframe.h>
44 #include <class_library.h>
45 #include <template_fieldnames.h>
47 #include <schframe.h>
48 #include <symbol_lib_table.h>
49 #include <lib_manager.h>
50 #include <cmp_tree_pane.h>
51 #include <component_tree.h>
52 
54 #include <cmp_tree_model_adapter.h>
55 
57 
58 
60 {
61  wxString lib = GetCurLib();
62  wxString title = _( "Symbol Library Editor - " );
63 
64  if( !lib.empty() && Prj().SchSymbolLibTable()->HasLibrary( lib ) )
65  {
66  wxString fileName = Prj().SchSymbolLibTable()->GetFullURI( lib );
67 
68  title += lib + " (" + fileName + ")";
69 
70  if( wxFileName::FileExists( fileName ) && !wxFileName::IsFileWritable( fileName ) )
71  title += " " + _( "[Read Only]" );
72  }
73  else
74  title += _( "no library selected" );
75 
76  SetTitle( title );
77 }
78 
79 
80 void LIB_EDIT_FRAME::SelectActiveLibrary( const wxString& aLibrary )
81 {
82  wxString selectedLib = aLibrary;
83 
84  if( selectedLib.empty() )
85  selectedLib = SelectLibraryFromList();
86 
87  if( !selectedLib.empty() )
88  SetCurLib( selectedLib );
89 
91 }
92 
93 
95 {
96  if( GetScreen()->IsModify()
97  && !IsOK( this, _( "The current symbol is not saved.\n\nDiscard current changes?" ) ) )
98  return false;
99 
101  return LoadComponentFromCurrentLib( aLibId.GetLibItemName() );
102 }
103 
104 
105 bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( const wxString& aAliasName, int aUnit,
106  int aConvert )
107 {
108  LIB_ALIAS* alias = nullptr;
109 
110  try
111  {
112  alias = Prj().SchSymbolLibTable()->LoadSymbol( GetCurLib(), aAliasName );
113  }
114  catch( const IO_ERROR& ioe )
115  {
116  wxString msg;
117 
118  msg.Printf( _( "Error occurred loading symbol \"%s\" from library \"%s\"." ),
119  aAliasName, GetCurLib() );
120  DisplayErrorMessage( this, msg, ioe.What() );
121  return false;
122  }
123 
124  if( !alias || !LoadOneLibraryPartAux( alias, GetCurLib() ) )
125  return false;
126 
127  if( aUnit > 0 )
128  m_unit = aUnit;
129 
130  if( aConvert > 0 )
131  m_convert = aConvert;
132 
133  m_editPinsSeparately = GetCurPart()->UnitsLocked() ? true : false;
134 
136  Zoom_Automatique( false );
137  SetShowDeMorgan( GetCurPart()->HasConversion() );
138 
139  if( aUnit > 0 )
141 
142  return true;
143 }
144 
145 
146 bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_ALIAS* aEntry, const wxString& aLibrary )
147 {
148  wxString msg, rootName;
149 
150  if( !aEntry || aLibrary.empty() )
151  return false;
152 
153  if( aEntry->GetName().IsEmpty() )
154  {
155  wxLogWarning( "Symbol in library \"%s\" has empty name field.", aLibrary );
156  return false;
157  }
158 
159  m_aliasName = aEntry->GetName();
160 
161  LIB_PART* lib_part = m_libMgr->GetBufferedPart( m_aliasName, aLibrary );
162  wxASSERT( lib_part );
163  SetScreen( m_libMgr->GetScreen( lib_part->GetName(), aLibrary ) );
164  SetCurPart( new LIB_PART( *lib_part ) );
165  SetCurLib( aLibrary );
166 
167  m_unit = 1;
168  m_convert = 1;
169  SetShowDeMorgan( GetCurPart()->HasConversion() );
170 
171  Zoom_Automatique( false );
172  DisplayLibInfos();
175 
176  // Display the document information based on the entry selected just in
177  // case the entry is an alias.
178  DisplayCmpDoc();
179  Refresh();
180 
181  return true;
182 }
183 
184 
185 void LIB_EDIT_FRAME::RedrawComponent( wxDC* aDC, wxPoint aOffset )
186 {
187  LIB_PART* part = GetCurPart();
188 
189  if( part )
190  {
191  // display reference like in schematic (a reference U is shown U? or U?A)
192  // although it is stored without ? and part id.
193  // So temporary change the reference by a schematic like reference
194  LIB_FIELD* field = part->GetField( REFERENCE );
195  wxString fieldText = field->GetText();
196  wxString fieldfullText = field->GetFullText( m_unit );
197 
198  field->EDA_TEXT::SetText( fieldfullText ); // change the field text string only
199  auto opts = PART_DRAW_OPTIONS::Default();
200  opts.show_elec_type = GetShowElectricalType();
201  part->Draw( m_canvas, aDC, aOffset, m_unit, m_convert, opts );
202  field->EDA_TEXT::SetText( fieldText ); // restore the field text string
203  }
204 }
205 
206 
207 void LIB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
208 {
209  if( GetScreen() == NULL )
210  return;
211 
212  m_canvas->DrawBackGround( DC );
213 
214  RedrawComponent( DC, wxPoint( 0, 0 ) );
215 
216 #ifdef USE_WX_OVERLAY
217  if( IsShown() )
218  {
219  m_overlay.Reset();
220  wxDCOverlay overlaydc( m_overlay, (wxWindowDC*)DC );
221  overlaydc.Clear();
222  }
223 #endif
224 
225  if( m_canvas->IsMouseCaptured() )
226  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
227 
228  m_canvas->DrawCrossHair( DC );
229 
230  DisplayLibInfos();
231  UpdateStatusBar();
232 }
233 
234 
235 void LIB_EDIT_FRAME::OnSaveLibrary( wxCommandEvent& event )
236 {
237  saveLibrary( getTargetLib(), event.GetId() == ID_LIBEDIT_SAVE_LIBRARY_AS );
238  m_treePane->Refresh();
239 }
240 
241 
242 void LIB_EDIT_FRAME::OnSaveAllLibraries( wxCommandEvent& event )
243 {
245 }
246 
247 
248 void LIB_EDIT_FRAME::OnRevertLibrary( wxCommandEvent& aEvent )
249 {
250  wxString libName = getTargetLib();
251  bool currentLib = ( libName == GetCurLib() );
252 
253  // Save the current part name/unit to reload after revert
254  wxString alias = m_aliasName;
255  int unit = m_unit;
256 
257  if( !IsOK( this, _( "The revert operation cannot be undone!\n\nRevert changes?" ) ) )
258  return;
259 
260  if( currentLib )
261  emptyScreen();
262 
263  m_libMgr->RevertLibrary( libName );
264 
265  if( currentLib && m_libMgr->PartExists( alias, libName ) )
266  loadPart( alias, libName, unit );
267 }
268 
269 
270 void LIB_EDIT_FRAME::OnCreateNewPart( wxCommandEvent& event )
271 {
273  SetDrawItem( NULL );
274  wxString lib = getTargetLib();
275 
276  if( !m_libMgr->LibraryExists( lib ) )
277  {
278  lib = SelectLibraryFromList();
279 
280  if( !m_libMgr->LibraryExists( lib ) )
281  return;
282  }
283 
284  DIALOG_LIB_NEW_COMPONENT dlg( this );
285  dlg.SetMinSize( dlg.GetSize() );
286 
287  if( dlg.ShowModal() == wxID_CANCEL )
288  return;
289 
290  if( dlg.GetName().IsEmpty() )
291  {
292  wxMessageBox( _( "This new symbol has no name and cannot be created." ) );
293  return;
294  }
295 
296  wxString name = dlg.GetName();
297  name.Replace( " ", "_" );
298 
299  // Test if there is a component with this name already.
300  if( !lib.empty() && m_libMgr->PartExists( name, lib ) )
301  {
302  wxString msg = wxString::Format( _( "Symbol \"%s\" already exists in library \"%s\"" ),
303  name, lib );
304  DisplayError( this, msg );
305  return;
306  }
307 
308  LIB_PART new_part( name ); // do not create part on the heap, it will be buffered soon
309  m_aliasName = name;
310  new_part.GetReferenceField().SetText( dlg.GetReference() );
311  new_part.SetUnitCount( dlg.GetUnitCount() );
312 
313  // Initialize new_part.m_TextInside member:
314  // if 0, pin text is outside the body (on the pin)
315  // if > 0, pin text is inside the body
316 
317  if( dlg.GetPinNameInside() )
318  {
319  new_part.SetPinNameOffset( dlg.GetPinTextPosition() );
320 
321  if( new_part.GetPinNameOffset() == 0 )
322  new_part.SetPinNameOffset( 1 );
323  }
324  else
325  {
326  new_part.SetPinNameOffset( 0 );
327  }
328 
329  ( dlg.GetPowerSymbol() ) ? new_part.SetPower() : new_part.SetNormal();
330  new_part.SetShowPinNumbers( dlg.GetShowPinNumber() );
331  new_part.SetShowPinNames( dlg.GetShowPinName() );
332  new_part.LockUnits( dlg.GetLockItems() );
333 
334  if( dlg.GetUnitCount() < 2 )
335  new_part.LockUnits( false );
336 
337  m_libMgr->UpdatePart( &new_part, lib );
338  loadPart( name, lib, 1 );
339 
340  new_part.SetConversion( dlg.GetAlternateBodyStyle() );
341  // must be called after loadPart, that calls SetShowDeMorgan, but
342  // because the symbol is empty,it looks like it has no alternate body
344 
345 }
346 
347 
348 void LIB_EDIT_FRAME::OnEditPart( wxCommandEvent& aEvent )
349 {
350  int unit = 0;
351  LIB_ID partId = m_treePane->GetCmpTree()->GetSelectedLibId( &unit );
352  loadPart( partId.GetLibItemName(), partId.GetLibNickname(), unit );
353 }
354 
355 
356 void LIB_EDIT_FRAME::OnSavePart( wxCommandEvent& aEvent )
357 {
358  LIB_ID libId = getTargetLibId();
359 
360  if( m_libMgr->FlushPart( libId.GetLibItemName(), libId.GetLibNickname() ) )
362 
363  m_treePane->Refresh();
364 }
365 
366 
367 void LIB_EDIT_FRAME::OnRemovePart( wxCommandEvent& aEvent )
368 {
369  LIB_ID libId = getTargetLibId();
370 
371  if( m_libMgr->IsPartModified( libId.GetLibItemName(), libId.GetLibNickname() )
372  && !IsOK( this, _( wxString::Format( "Component %s has been modified\n"
373  "Do you want to remove it from the library?", libId.GetLibItemName().c_str() ) ) ) )
374  {
375  return;
376  }
377 
378  if( isCurrentPart( libId ) )
379  emptyScreen();
380 
381  m_libMgr->RemovePart( libId.GetLibItemName(), libId.GetLibNickname() );
382 }
383 
384 
385 void LIB_EDIT_FRAME::OnCopyCutPart( wxCommandEvent& aEvent )
386 {
387  int unit = 0;
388  auto cmpTree = m_treePane->GetCmpTree();
389  LIB_ID partId = cmpTree->GetSelectedLibId( &unit );
390  LIB_PART* part = m_libMgr->GetBufferedPart( partId.GetLibItemName(), partId.GetLibNickname() );
391 
392  if( !part )
393  return;
394 
395  LIB_ID libId = getTargetLibId();
396  m_copiedPart.reset( new LIB_PART( *part ) );
397 
398  if( aEvent.GetId() == ID_LIBEDIT_CUT_PART )
399  {
400  if( isCurrentPart( libId ) )
401  emptyScreen();
402 
403  m_libMgr->RemovePart( libId.GetLibItemName(), libId.GetLibNickname() );
404  }
405 }
406 
407 
408 void LIB_EDIT_FRAME::OnPasteDuplicatePart( wxCommandEvent& aEvent )
409 {
410  int unit = 0;
411  LIB_ID libId = m_treePane->GetCmpTree()->GetSelectedLibId( &unit );
412  wxString lib = libId.GetLibNickname();
413 
414  if( !m_libMgr->LibraryExists( lib ) )
415  return;
416 
417  LIB_PART* srcPart = nullptr;
418 
419  if( aEvent.GetId() == ID_LIBEDIT_DUPLICATE_PART )
420  srcPart = m_libMgr->GetBufferedPart( libId.GetLibItemName(), lib );
421  else if( aEvent.GetId() == ID_LIBEDIT_PASTE_PART )
422  srcPart = m_copiedPart.get();
423  else
424  wxFAIL;
425 
426  if( !srcPart )
427  return;
428 
429  LIB_PART newPart( *srcPart );
430  fixDuplicateAliases( &newPart, lib );
431  m_libMgr->UpdatePart( &newPart, lib );
432  m_treePane->GetCmpTree()->SelectLibId( LIB_ID( lib, newPart.GetName() ) );
433 }
434 
435 
436 void LIB_EDIT_FRAME::fixDuplicateAliases( LIB_PART* aPart, const wxString& aLibrary )
437 {
438  wxString newName;
439 
440  for( unsigned int i = 0; i < aPart->GetAliasCount(); ++i )
441  {
442  LIB_ALIAS* alias = aPart->GetAlias( i );
443  int sfx = 0;
444  newName = alias->GetName();
445 
446  while( m_libMgr->PartExists( newName, aLibrary ) )
447  {
448  newName = wxString::Format( "%s_%d", alias->GetName(), sfx );
449  ++sfx;
450  }
451 
452  if( i == 0 )
453  aPart->SetName( newName );
454  else
455  alias->SetName( newName );
456  }
457 }
458 
459 
460 void LIB_EDIT_FRAME::OnRevertPart( wxCommandEvent& aEvent )
461 {
462  LIB_ID libId = getTargetLibId();
463  bool currentPart = isCurrentPart( libId );
464  int unit = m_unit;
465 
466  if( currentPart )
467  emptyScreen();
468 
469  if( m_libMgr->RevertPart( libId.GetLibItemName(), libId.GetLibNickname() ) )
471 
472  if( currentPart && m_libMgr->PartExists( libId.GetLibItemName(), libId.GetLibNickname() ) )
473  loadPart( libId.GetLibItemName(), libId.GetLibNickname(), unit );
474 }
475 
476 
477 void LIB_EDIT_FRAME::loadPart( const wxString& aAlias, const wxString& aLibrary, int aUnit )
478 {
479  wxCHECK( m_libMgr->PartExists( aAlias, aLibrary ), /* void */ );
480  LIB_PART* part = m_libMgr->GetBufferedPart( aAlias, aLibrary );
481  LIB_ALIAS* alias = part ? part->GetAlias( aAlias ) : nullptr;
482 
483  if( !alias )
484  {
485  wxString msg = wxString::Format( _( "Part name \"%s\" not found in library \"%s\"" ),
486  GetChars( aAlias ), GetChars( aLibrary ) );
487  DisplayError( this, msg );
488  return;
489  }
490 
491  m_lastDrawItem = nullptr;
492  SetDrawItem( NULL );
493  m_aliasName = aAlias;
494  m_unit = ( aUnit <= part->GetUnitCount() ? aUnit : 1 );
495 
496  // Optimize default edit options for this symbol
497  // Usually if units are locked, graphic items are specific to each unit
498  // and if units are interchangeable, graphic items are common to units
499  m_drawSpecificUnit = part->UnitsLocked() ? true : false;
500 
501  LoadOneLibraryPartAux( alias, aLibrary );
502 }
503 
504 
505 bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
506 {
507  wxFileName fn;
508  wxString msg;
509  PROJECT& prj = Prj();
510 
512 
513  if( !aNewFile && ( aLibrary.empty() || !prj.SchSymbolLibTable()->HasLibrary( aLibrary ) ) )
514  {
515  DisplayError( this, _( "No library specified." ) );
516  return false;
517  }
518 
519  if( aNewFile )
520  {
521  SEARCH_STACK* search = prj.SchSearchS();
522 
523  // Get a new name for the library
524  wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH );
525 
526  if( !default_path )
527  default_path = search->LastVisitedPath();
528 
529  fn.SetName( aLibrary );
530  fn.SetExt( SchematicLibraryFileExtension );
531 
532  wxFileDialog dlg( this, wxString::Format( _( "Save Library \"%s\" As..." ), aLibrary ),
533  default_path, fn.GetFullName(), SchematicLibraryFileWildcard(),
534  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
535 
536  if( dlg.ShowModal() == wxID_CANCEL )
537  return false;
538 
539  fn = dlg.GetPath();
540 
541  // The GTK file chooser doesn't return the file extension added to
542  // file name so add it here.
543  if( fn.GetExt().IsEmpty() )
544  fn.SetExt( SchematicLibraryFileExtension );
545  }
546  else
547  {
548  fn = prj.SchSymbolLibTable()->GetFullURI( aLibrary );
549  }
550 
551  // Verify the user has write privileges before attempting to save the library file.
552  if( !IsWritable( fn ) )
553  return false;
554 
555  ClearMsgPanel();
556 
557  // Copy .lib file to .bak.
558  if( !backupFile( fn, "bak" ) )
559  return false;
560 
561  wxFileName docFileName = fn;
562  docFileName.SetExt( DOC_EXT );
563 
564  // Copy .dcm file to .bck.
565  if( !backupFile( docFileName, "bck" ) )
566  return false;
567 
568  if( !m_libMgr->SaveLibrary( aLibrary, fn.GetFullPath() ) )
569  {
570  msg.Printf( _( "Failed to save changes to symbol library file \"%s\"" ),
571  fn.GetFullPath() );
572  DisplayErrorMessage( this, _( "Error saving library" ), msg );
573  return false;
574  }
575 
576  if( !aNewFile )
577  m_libMgr->ClearLibraryModified( aLibrary );
578 
579  msg.Printf( _( "Symbol library file \"%s\" saved" ), fn.GetFullPath() );
580  wxString msg1;
581  msg1.Printf( _( "Symbol library documentation file \"%s\" saved" ), docFileName.GetFullPath() );
582  AppendMsgPanel( msg, msg1, BLUE );
586 
587  return true;
588 }
589 
590 
592 {
593  wxArrayString unsavedLibraries;
594  // There are two stages: first try to save libraries to the original files.
595  // In case of problems, ask the user to save them in a new location.
596  bool firstRun = true;
597  bool allSaved = false;
598 
599  while( !allSaved )
600  {
601  allSaved = true;
602  unsavedLibraries.Empty();
603 
604  for( const auto& lib : m_libMgr->GetLibraryNames() )
605  {
606  if( m_libMgr->IsLibraryModified( lib ) )
607  unsavedLibraries.Add( lib );
608  }
609 
610  if( !unsavedLibraries.IsEmpty() )
611  {
612  auto res = SelectMultipleOptions( this, _( "Save Libraries" ),
613  firstRun ? _( "Select libraries to save before closing" )
614  : _( "Some libraries could not be saved to their original files.\n\n"
615  "Do you want to save them to a new file?" ),
616  unsavedLibraries, true );
617 
618  if( !res.first )
619  return false; // dialog has been cancelled
620 
621  for( auto libIndex : res.second )
622  allSaved &= saveLibrary( unsavedLibraries[libIndex], !firstRun );
623 
624  firstRun = false;
625  }
626  }
627 
628  return true;
629 }
630 
631 
633 {
634  LIB_ALIAS* alias;
635  LIB_PART* part = GetCurPart();
636 
637  ClearMsgPanel();
638 
639  if( !part )
640  return;
641 
642  wxString msg = part->GetName();
643 
644  AppendMsgPanel( _( "Name" ), msg, BLUE, 8 );
645 
646  if( m_aliasName == part->GetName() )
647  msg = _( "None" );
648  else
649  msg = m_aliasName;
650 
651  alias = part->GetAlias( m_aliasName );
652 
653  wxCHECK_RET( alias != NULL, "Alias not found in symbol." );
654 
655  AppendMsgPanel( _( "Alias" ), msg, RED, 8 );
656 
657  static wxChar UnitLetter[] = wxT( "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
658  msg = UnitLetter[m_unit];
659 
660  AppendMsgPanel( _( "Unit" ), msg, BROWN, 8 );
661 
662  if( m_convert > 1 )
663  msg = _( "Convert" );
664  else
665  msg = _( "Normal" );
666 
667  AppendMsgPanel( _( "Body" ), msg, GREEN, 8 );
668 
669  if( part->IsPower() )
670  msg = _( "Power Symbol" );
671  else
672  msg = _( "Part" );
673 
674  AppendMsgPanel( _( "Type" ), msg, MAGENTA, 8 );
675  AppendMsgPanel( _( "Description" ), alias->GetDescription(), CYAN, 8 );
676  AppendMsgPanel( _( "Key words" ), alias->GetKeyWords(), DARKDARKGRAY );
677  AppendMsgPanel( _( "Datasheet" ), alias->GetDocFileName(), DARKDARKGRAY );
678 }
Definition: colors.h:57
bool UnitsLocked() const
LIB_FIELD * GetField(int aId)
Return pointer to the requested field.
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDc, const wxPoint &aOffset, int aMulti, int aConvert, const PART_DRAW_OPTIONS &aOpts)
Draw part.
Part library alias object definition.
std::unique_ptr< LIB_PART > m_copiedPart
Definition: libeditframe.h:766
void SetConversion(bool aSetConvert)
Set or clear the alternate body style (DeMorgan) for the part.
void SetPower()
bool LoadComponentFromCurrentLib(const wxString &aAliasName, int aUnit=0, int aConvert=0)
Loads a symbol from the current active library, optionally setting the selected unit and convert...
Definition: libedit.cpp:105
Class PROJECT holds project specific data.
Definition: project.h:56
int GetPinNameOffset()
static int m_convert
Definition: libeditframe.h:116
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:88
This file is part of the common library TODO brief description.
bool IsPower() const
LIB_ALIAS * GetAlias(size_t aIndex)
wxString SelectLibraryFromList()
Dispaly a list of loaded libraries in the symbol library and allows the user to select a library...
Definition: selpart.cpp:76
void OnCreateNewPart(wxCommandEvent &aEvent)
Creates a new part in the selected library.
Definition: libedit.cpp:270
This file is part of the common library.
bool RemovePart(const wxString &aName, const wxString &aLibrary)
Removes the part from the part buffer.
void SetScreen(BASE_SCREEN *aScreen)
Definition: draw_frame.h:144
Definition: colors.h:61
bool isCurrentPart(const LIB_ID &aLibId) const
Returns true if currently modified part has the same LIB_ID.
Field object used in symbol libraries.
Definition: lib_field.h:59
void DrawCrossHair(wxDC *aDC, COLOR4D aColor=COLOR4D::WHITE)
Function DrawCrossHair draws the user cross hair.
Definition: draw_panel.cpp:222
LIB_MANAGER * m_libMgr
manager taking care of temporary modificatoins
Definition: libeditframe.h:67
void SelectActiveLibrary(const wxString &aLibrary=wxEmptyString)
Set the current active library to aLibrary.
Definition: libedit.cpp:80
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
bool ClearLibraryModified(const wxString &aLibrary) const
Clears the modified flag for all parts in a library.
wxString SchematicLibraryFileWildcard()
void EndMouseCapture(int aId=-1, int aCursorId=-1, const wxString &aTitle=wxEmptyString, bool aCallEndFunc=true)
Function EndMouseCapture ends mouse a capture.
LIB_ID getTargetLibId() const
Returns either the part selected in the component tree, if context menu is active or the currently mo...
Class SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:358
bool RevertPart(const wxString &aAlias, const wxString &aLibrary)
Reverts unsaved changes for a particular part.
bool IsWritable(const wxFileName &aFileName)
Function IsWritable checks if aFileName can be written.
Definition: basicframe.cpp:538
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
size_t GetAliasCount() const
void fixDuplicateAliases(LIB_PART *aPart, const wxString &aLibrary)
Renames LIB_PART aliases to avoid conflicts before adding a component to a library ...
Definition: libedit.cpp:436
void UpdateAliasSelectList()
Field Reference of part, i.e. "IC21".
void OnSavePart(wxCommandEvent &aEvent)
Saves a single part in the selected library.
Definition: libedit.cpp:356
void SetShowDeMorgan(bool show)
Definition: libeditframe.h:446
This file contains miscellaneous commonly used macros and functions.
void DisplayLibInfos()
Updates the main window title bar with the current library name and read only status of the library...
Definition: libedit.cpp:59
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void Zoom_Automatique(bool aWarpPointer)
Function Zoom_Automatique redraws the screen with best zoom level and the best centering that shows a...
Definition: zoom.cpp:77
void SetName(const wxString &aName)
Subclass of DIALOG_LIB_NEW_COMPONENT, which is generated by wxFormBuilder.
bool saveAllLibraries()
Returns true when the operation has succeded (all requested libraries have been saved or none was sel...
Definition: libedit.cpp:591
LIB_PART * GetCurPart() const
Return the current part being edited or NULL if none selected.
Definition: libeditframe.h:166
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
bool saveLibrary(const wxString &aLibrary, bool aNewFile)
Saves the changes to the current library.
Definition: libedit.cpp:505
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit components, if the user selects the component itself rather than picking an individual...
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:504
void Refresh()
Update the board display after modifying it bu a python script (note: it is automatically called by a...
void SetDrawItem(LIB_ITEM *drawItem)
Definition: libeditframe.h:442
void SetUnitCount(int count)
Set the units per part count.
void OnPasteDuplicatePart(wxCommandEvent &aEvent)
Definition: libedit.cpp:408
bool IsMouseCaptured() const
Definitions for the Eeschema program SCH_SCREEN class.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
bool ClearPartModified(const wxString &aAlias, const wxString &aLibrary) const
Clears the modified flag for a part.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
SCH_SCREEN * GetScreen(const wxString &aAlias, const wxString &aLibrary)
Returns the screen used to edit a specific part.
wxString GetDescription() const
bool LibraryExists(const wxString &aLibrary) const
Returns true if library exists.
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
Definition: colors.h:59
void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
void OnRemovePart(wxCommandEvent &aEvent)
Removes a part from the working copy of a library.
Definition: libedit.cpp:367
Define a library symbol object.
The common library.
#define DOC_EXT
Definition: class_library.h:50
bool IsLibraryModified(const wxString &aLibrary) const
Returns true if library has unsaved modifications.
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
Definition: colors.h:60
wxString GetName(void) const override
static LIB_ITEM * m_lastDrawItem
Definition: libeditframe.h:108
bool FlushPart(const wxString &aAlias, const wxString &aLibrary)
Saves part changes to the library copy used by the schematic editor.
static PART_DRAW_OPTIONS Default()
void OnRevertLibrary(wxCommandEvent &aEvent)
Reverts unsaved changes in a library.
Definition: libedit.cpp:248
bool SaveLibrary(const wxString &aLibrary, const wxString &aFileName)
Saves library to a file, including unsaved changes.
void emptyScreen()
Restores the empty editor screen, without any part or library selected.
bool UpdatePart(LIB_PART *aPart, const wxString &aLibrary)
Updates the part buffer with a new version of the part.
void DisplayCmpDoc()
Display the documentation of the selected component.
Definition: libedit.cpp:632
void SelectLibId(const LIB_ID &aLibId)
Select a part in the tree widget.
void UpdateStatusBar() override
Function UpdateStatusBar updates the status bar information.
bool backupFile(const wxFileName &aOriginalFile, const wxString &aBackupExt)
Creates a backup copy of a file with requested extension
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
Definition: draw_frame.cpp:768
wxString getTargetLib() const
Returns either the library selected in the component tree, if context menu is active or the library t...
wxString GetDocFileName() const
VTBL_ENTRY const wxString & GetRString(RSTRING_T aStringId)
Function GetRString returns a "retained string", which is any session and project specific string ide...
Definition: project.cpp:186
LIB_PART * GetBufferedPart(const wxString &aAlias, const wxString &aLibrary)
Returns the part copy from the buffer.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void OnRevertPart(wxCommandEvent &aEvent)
Reverts unsaved changes in a part, restoring to the last saved state.
Definition: libedit.cpp:460
bool PartExists(const wxString &aAlias, const wxString &aLibrary) const
Returns true if part with a specific alias exists in library (either original one or buffered)...
wxArrayString GetLibraryNames() const
Returns the array of library names.
Definition: lib_manager.cpp:82
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
bool LoadOneLibraryPartAux(LIB_ALIAS *aLibEntry, const wxString &aLibrary)
Create a copy of aLibEntry into memory.
Definition: libedit.cpp:146
Definition: colors.h:58
see class PGM_BASE
static wxString m_aliasName
Definition: libeditframe.h:109
static int m_unit
Definition: libeditframe.h:112
const wxString & GetName() const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
std::pair< bool, std::vector< int > > SelectMultipleOptions(wxWindow *aParent, const wxString &aTitle, const wxString &aMessage, const wxArrayString &aOptions, bool aDefaultState)
Displays a dialog with checkboxes asking the user to select one or more options.
Definition: confirm.cpp:304
void OnEditPart(wxCommandEvent &aEvent)
Opens the selected part for editing.
Definition: libedit.cpp:348
void OnCopyCutPart(wxCommandEvent &aEvent)
Definition: libedit.cpp:385
void SetCurPart(LIB_PART *aPart)
Take ownership of aPart and notes that it is the one currently being edited.
void RedrawComponent(wxDC *aDC, wxPoint aOffset)
Redraw the current component loaded in library editor Display reference like in schematic (a referenc...
Definition: libedit.cpp:185
const char * c_str() const
Definition: utf8.h:107
const wxString LastVisitedPath(const wxString &aSubPathToSearch=wxEmptyString)
Function LastVisitedPath is a quirky function inherited from old code that seems to serve particular ...
bool m_editPinsSeparately
Set to true to not synchronize pins at the same position when editing symbols with multiple units or ...
Definition: libeditframe.h:95
const char * name
const wxString & GetName() const
virtual void SetName(const wxString &aName)
bool IsPartModified(const wxString &aAlias, const wxString &aLibrary) const
Returns true if part has unsaved modifications.
Implementing DIALOG_LIB_NEW_COMPONENT.
wxString SetCurLib(const wxString &aLibNickname)
Sets the current library nickname and returns the old library nickname.
void DrawBackGround(wxDC *DC)
Function DrawBackGround.
Definition: draw_panel.cpp:688
COMPONENT_TREE * GetCmpTree() const
Definition: cmp_tree_pane.h:46
bool LoadComponentAndSelectLib(const LIB_ID &aLibId)
Selects the currently active library and loads the symbol from aLibId.
Definition: libedit.cpp:94
Definition for part library class.
void OnSaveAllLibraries(wxCommandEvent &event)
Saves all changes in modified libraries.
Definition: libedit.cpp:242
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:98
bool m_drawSpecificUnit
Specify which component parts the current draw item applies to.
Definition: libeditframe.h:78
void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
void RedrawActiveWindow(wxDC *DC, bool EraseBg) override
Redraw the current component loaded in library editor, an axes Display reference like in schematic (a...
Definition: libedit.cpp:207
int GetDefaultCursor() const
Function GetDefaultCursor.
const wxString SchematicLibraryFileExtension
void OnSaveLibrary(wxCommandEvent &event)
The command event handler to save the changes to the current library.
Definition: libedit.cpp:235
wxString GetKeyWords() const
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:74
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:122
void UpdatePartSelectList()
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:779
Definition of class LIB_EDIT_FRAME.
bool GetShowElectricalType()
Definition: libeditframe.h:448
void loadPart(const wxString &aLibrary, const wxString &aPart, int Unit)
Definition: libedit.cpp:477
CMP_TREE_PANE * m_treePane
component search tree widget
Definition: libeditframe.h:66
void LockUnits(bool aLockUnits)
bool RevertLibrary(const wxString &aLibrary)
Reverts unsaved changes for a particular library.
void SetNormal()
Definition: colors.h:62