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 
40 #include <eeschema_id.h>
41 #include <general.h>
42 #include <lib_edit_frame.h>
43 #include <class_library.h>
44 #include <template_fieldnames.h>
46 #include <sch_edit_frame.h>
47 #include <symbol_lib_table.h>
48 #include <lib_manager.h>
49 #include <cmp_tree_pane.h>
50 #include <component_tree.h>
51 
53 #include <cmp_tree_model_adapter.h>
54 
56 
57 
59 {
60  wxString lib = GetCurLib();
61  wxString title = _( "Symbol Library Editor - " );
62 
63  if( !lib.empty() && Prj().SchSymbolLibTable()->HasLibrary( lib ) )
64  {
65  wxString fileName = Prj().SchSymbolLibTable()->GetFullURI( lib );
66 
67  title += lib + " (" + fileName + ")";
68 
69  if( wxFileName::FileExists( fileName ) && !wxFileName::IsFileWritable( fileName ) )
70  title += " " + _( "[Read Only]" );
71  }
72  else
73  title += _( "no library selected" );
74 
75  SetTitle( title );
76 }
77 
78 
79 void LIB_EDIT_FRAME::SelectActiveLibrary( const wxString& aLibrary )
80 {
81  wxString selectedLib = aLibrary;
82 
83  if( selectedLib.empty() )
84  selectedLib = SelectLibraryFromList();
85 
86  if( !selectedLib.empty() )
87  SetCurLib( selectedLib );
88 
90 }
91 
92 
94 {
95  if( GetScreen()->IsModify()
96  && !IsOK( this, _( "The current symbol is not saved.\n\nDiscard current changes?" ) ) )
97  return false;
98 
100  return LoadComponentFromCurrentLib( aLibId.GetLibItemName() );
101 }
102 
103 
104 bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( const wxString& aAliasName, int aUnit,
105  int aConvert )
106 {
107  LIB_ALIAS* alias = nullptr;
108 
109  try
110  {
111  alias = Prj().SchSymbolLibTable()->LoadSymbol( GetCurLib(), aAliasName );
112  }
113  catch( const IO_ERROR& ioe )
114  {
115  wxString msg;
116 
117  msg.Printf( _( "Error occurred loading symbol \"%s\" from library \"%s\"." ),
118  aAliasName, GetCurLib() );
119  DisplayErrorMessage( this, msg, ioe.What() );
120  return false;
121  }
122 
123  if( !alias || !LoadOneLibraryPartAux( alias, GetCurLib() ) )
124  return false;
125 
126  if( aUnit > 0 )
127  m_unit = aUnit;
128 
129  if( aConvert > 0 )
130  m_convert = aConvert;
131 
132  // Enable synchronized pin edit mode for symbols with interchangeable units
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 {
244  saveAllLibraries( false );
245  m_treePane->Refresh();
246 }
247 
248 
249 void LIB_EDIT_FRAME::OnRevertLibrary( wxCommandEvent& aEvent )
250 {
251  wxString libName = getTargetLib();
252  wxString curLib = GetCurLib();
253  bool currentLib = ( libName == curLib || curLib.IsEmpty() );
254 
255  // Save the current part name/unit to reload after revert
256  wxString alias = m_aliasName;
257  int unit = m_unit;
258 
259  if( !IsOK( this, _( "The revert operation cannot be undone!\n\nRevert changes?" ) ) )
260  return;
261 
262  if( currentLib )
263  emptyScreen();
264 
265  m_libMgr->RevertLibrary( libName );
266 
267  if( currentLib && m_libMgr->PartExists( alias, libName ) )
268  loadPart( alias, libName, unit );
269 }
270 
271 
272 void LIB_EDIT_FRAME::OnCreateNewPart( wxCommandEvent& event )
273 {
275  SetDrawItem( NULL );
276  wxString lib = getTargetLib();
277 
278  if( !m_libMgr->LibraryExists( lib ) )
279  {
280  lib = SelectLibraryFromList();
281 
282  if( !m_libMgr->LibraryExists( lib ) )
283  return;
284  }
285 
286  DIALOG_LIB_NEW_COMPONENT dlg( this );
287  dlg.SetMinSize( dlg.GetSize() );
288 
289  if( dlg.ShowModal() == wxID_CANCEL )
290  return;
291 
292  if( dlg.GetName().IsEmpty() )
293  {
294  wxMessageBox( _( "This new symbol has no name and cannot be created." ) );
295  return;
296  }
297 
298  wxString name = dlg.GetName();
299  // Currently, symbol names cannot include a space, that breaks libraries:
300  name.Replace( " ", "_" );
301 
302  // Test if there is a component with this name already.
303  if( !lib.empty() && m_libMgr->PartExists( name, lib ) )
304  {
305  wxString msg = wxString::Format( _( "Symbol \"%s\" already exists in library \"%s\"" ),
306  name, lib );
307  DisplayError( this, msg );
308  return;
309  }
310 
311  LIB_PART new_part( name ); // do not create part on the heap, it will be buffered soon
312  m_aliasName = name;
313  new_part.GetReferenceField().SetText( dlg.GetReference() );
314  new_part.SetUnitCount( dlg.GetUnitCount() );
315 
316  // Initialize new_part.m_TextInside member:
317  // if 0, pin text is outside the body (on the pin)
318  // if > 0, pin text is inside the body
319 
320  if( dlg.GetPinNameInside() )
321  {
322  new_part.SetPinNameOffset( dlg.GetPinTextPosition() );
323 
324  if( new_part.GetPinNameOffset() == 0 )
325  new_part.SetPinNameOffset( 1 );
326  }
327  else
328  {
329  new_part.SetPinNameOffset( 0 );
330  }
331 
332  ( dlg.GetPowerSymbol() ) ? new_part.SetPower() : new_part.SetNormal();
333  new_part.SetShowPinNumbers( dlg.GetShowPinNumber() );
334  new_part.SetShowPinNames( dlg.GetShowPinName() );
335  new_part.LockUnits( dlg.GetLockItems() );
336 
337  if( dlg.GetUnitCount() < 2 )
338  new_part.LockUnits( false );
339 
340  m_libMgr->UpdatePart( &new_part, lib );
341  loadPart( name, lib, 1 );
342 
343  new_part.SetConversion( dlg.GetAlternateBodyStyle() );
344  // must be called after loadPart, that calls SetShowDeMorgan, but
345  // because the symbol is empty,it looks like it has no alternate body
347 
348 }
349 
350 
351 void LIB_EDIT_FRAME::OnEditPart( wxCommandEvent& aEvent )
352 {
353  int unit = 0;
354  LIB_ID partId = m_treePane->GetCmpTree()->GetSelectedLibId( &unit );
355  loadPart( partId.GetLibItemName(), partId.GetLibNickname(), unit );
356 }
357 
358 
359 void LIB_EDIT_FRAME::OnSavePart( wxCommandEvent& aEvent )
360 {
361  LIB_ID libId = getTargetLibId();
362 
363  if( m_libMgr->FlushPart( libId.GetLibItemName(), libId.GetLibNickname() ) )
365 
366  m_treePane->Refresh();
367 }
368 
369 
370 void LIB_EDIT_FRAME::OnRemovePart( wxCommandEvent& aEvent )
371 {
372  LIB_ID libId = getTargetLibId();
373 
374  if( m_libMgr->IsPartModified( libId.GetLibItemName(), libId.GetLibNickname() )
375  && !IsOK( this, _( wxString::Format( "Component %s has been modified\n"
376  "Do you want to remove it from the library?",
377  libId.GetUniStringLibItemName() ) ) ) )
378  {
379  return;
380  }
381 
382  if( isCurrentPart( libId ) )
383  emptyScreen();
384 
385  m_libMgr->RemovePart( libId.GetLibItemName(), libId.GetLibNickname() );
386 }
387 
388 
389 void LIB_EDIT_FRAME::OnCopyCutPart( wxCommandEvent& aEvent )
390 {
391  int unit = 0;
392  auto cmpTree = m_treePane->GetCmpTree();
393  LIB_ID partId = cmpTree->GetSelectedLibId( &unit );
394  LIB_PART* part = m_libMgr->GetBufferedPart( partId.GetLibItemName(), partId.GetLibNickname() );
395 
396  if( !part )
397  return;
398 
399  LIB_ID libId = getTargetLibId();
400  m_copiedPart.reset( new LIB_PART( *part ) );
401 
402  if( aEvent.GetId() == ID_LIBEDIT_CUT_PART )
403  {
404  if( isCurrentPart( libId ) )
405  emptyScreen();
406 
407  m_libMgr->RemovePart( libId.GetLibItemName(), libId.GetLibNickname() );
408  }
409 }
410 
411 
412 void LIB_EDIT_FRAME::OnPasteDuplicatePart( wxCommandEvent& aEvent )
413 {
414  int unit = 0;
415  LIB_ID libId = m_treePane->GetCmpTree()->GetSelectedLibId( &unit );
416  wxString lib = libId.GetLibNickname();
417 
418  if( !m_libMgr->LibraryExists( lib ) )
419  return;
420 
421  LIB_PART* srcPart = nullptr;
422 
423  if( aEvent.GetId() == ID_LIBEDIT_DUPLICATE_PART )
424  srcPart = m_libMgr->GetBufferedPart( libId.GetLibItemName(), lib );
425  else if( aEvent.GetId() == ID_LIBEDIT_PASTE_PART )
426  srcPart = m_copiedPart.get();
427  else
428  wxFAIL;
429 
430  if( !srcPart )
431  return;
432 
433  LIB_PART newPart( *srcPart );
434  fixDuplicateAliases( &newPart, lib );
435  m_libMgr->UpdatePart( &newPart, lib );
436  m_treePane->GetCmpTree()->SelectLibId( LIB_ID( lib, newPart.GetName() ) );
437 }
438 
439 
440 void LIB_EDIT_FRAME::fixDuplicateAliases( LIB_PART* aPart, const wxString& aLibrary )
441 {
442  wxString newName;
443 
444  for( unsigned int i = 0; i < aPart->GetAliasCount(); ++i )
445  {
446  LIB_ALIAS* alias = aPart->GetAlias( i );
447  int sfx = 0;
448  newName = alias->GetName();
449 
450  while( m_libMgr->PartExists( newName, aLibrary ) )
451  {
452  newName = wxString::Format( "%s_%d", alias->GetName(), sfx );
453  ++sfx;
454  }
455 
456  if( i == 0 )
457  aPart->SetName( newName );
458  else
459  alias->SetName( newName );
460  }
461 }
462 
463 
464 void LIB_EDIT_FRAME::OnRevertPart( wxCommandEvent& aEvent )
465 {
466  LIB_ID libId = getTargetLibId();
467  bool currentPart = isCurrentPart( libId );
468  int unit = m_unit;
469 
470  if( currentPart )
471  emptyScreen();
472 
473  libId = m_libMgr->RevertPart( libId.GetLibItemName(), libId.GetLibNickname() );
474 
475  m_treePane->GetCmpTree()->SelectLibId( libId );
477 
478  if( currentPart && m_libMgr->PartExists( libId.GetLibItemName(), libId.GetLibNickname() ) )
479  loadPart( libId.GetLibItemName(), libId.GetLibNickname(), unit );
480 }
481 
482 
483 void LIB_EDIT_FRAME::loadPart( const wxString& aAlias, const wxString& aLibrary, int aUnit )
484 {
485  wxCHECK( m_libMgr->PartExists( aAlias, aLibrary ), /* void */ );
486  LIB_PART* part = m_libMgr->GetBufferedPart( aAlias, aLibrary );
487  LIB_ALIAS* alias = part ? part->GetAlias( aAlias ) : nullptr;
488 
489  if( !alias )
490  {
491  wxString msg = wxString::Format( _( "Symbol name \"%s\" not found in library \"%s\"" ),
492  GetChars( aAlias ), GetChars( aLibrary ) );
493  DisplayError( this, msg );
494  return;
495  }
496 
497  m_lastDrawItem = nullptr;
498  SetDrawItem( NULL );
499  m_aliasName = aAlias;
500  m_unit = ( aUnit <= part->GetUnitCount() ? aUnit : 1 );
501 
502  // Optimize default edit options for this symbol
503  // Usually if units are locked, graphic items are specific to each unit
504  // and if units are interchangeable, graphic items are common to units
505  m_drawSpecificUnit = part->UnitsLocked() ? true : false;
506 
507  LoadOneLibraryPartAux( alias, aLibrary );
508 }
509 
510 
511 bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
512 {
513  wxFileName fn;
514  wxString msg;
515  PROJECT& prj = Prj();
516 
518 
519  if( !aNewFile && ( aLibrary.empty() || !prj.SchSymbolLibTable()->HasLibrary( aLibrary ) ) )
520  {
521  DisplayError( this, _( "No library specified." ) );
522  return false;
523  }
524 
525  if( aNewFile )
526  {
527  SEARCH_STACK* search = prj.SchSearchS();
528 
529  // Get a new name for the library
530  wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH );
531 
532  if( !default_path )
533  default_path = search->LastVisitedPath();
534 
535  fn.SetName( aLibrary );
536  fn.SetExt( SchematicLibraryFileExtension );
537 
538  wxFileDialog dlg( this, wxString::Format( _( "Save Library \"%s\" As..." ), aLibrary ),
539  default_path, fn.GetFullName(), SchematicLibraryFileWildcard(),
540  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
541 
542  if( dlg.ShowModal() == wxID_CANCEL )
543  return false;
544 
545  fn = dlg.GetPath();
546 
547  // The GTK file chooser doesn't return the file extension added to
548  // file name so add it here.
549  if( fn.GetExt().IsEmpty() )
550  fn.SetExt( SchematicLibraryFileExtension );
551  }
552  else
553  {
554  fn = prj.SchSymbolLibTable()->GetFullURI( aLibrary );
555  }
556 
557  // Verify the user has write privileges before attempting to save the library file.
558  if( !IsWritable( fn ) )
559  return false;
560 
561  ClearMsgPanel();
562 
563  // Copy .lib file to .bak.
564  if( !backupFile( fn, "bak" ) )
565  return false;
566 
567  wxFileName docFileName = fn;
568  docFileName.SetExt( DOC_EXT );
569 
570  // Copy .dcm file to .bck.
571  if( !backupFile( docFileName, "bck" ) )
572  return false;
573 
574  if( !m_libMgr->SaveLibrary( aLibrary, fn.GetFullPath() ) )
575  {
576  msg.Printf( _( "Failed to save changes to symbol library file \"%s\"" ),
577  fn.GetFullPath() );
578  DisplayErrorMessage( this, _( "Error saving library" ), msg );
579  return false;
580  }
581 
582  if( !aNewFile )
583  m_libMgr->ClearLibraryModified( aLibrary );
584 
585  msg.Printf( _( "Symbol library file \"%s\" saved" ), fn.GetFullPath() );
586  wxString msg1;
587  msg1.Printf( _( "Symbol library documentation file \"%s\" saved" ), docFileName.GetFullPath() );
588  AppendMsgPanel( msg, msg1, BLUE );
592 
593  return true;
594 }
595 
596 
597 bool LIB_EDIT_FRAME::saveAllLibraries( bool aClosing )
598 {
599  wxArrayString unsavedLibraries;
600  // There are two stages: first try to save libraries to the original files.
601  // In case of problems, ask the user to save them in a new location.
602  bool firstRun = true;
603  bool allSaved = false;
604 
605  while( !allSaved )
606  {
607  allSaved = true;
608  unsavedLibraries.Empty();
609 
610  for( const auto& lib : m_libMgr->GetLibraryNames() )
611  {
612  if( m_libMgr->IsLibraryModified( lib ) )
613  unsavedLibraries.Add( lib );
614  }
615 
616  if( unsavedLibraries.IsEmpty() )
617  break;
618 
619  wxArrayInt libIdxs;
620 
621  // Show a list of unsaved libraries when:
622  // - library editor is closed
623  // - there are multiple libraries modified
624  // - another library is opened
625  // - an error occurred when saving a library
626  if( aClosing || unsavedLibraries.Count() > 1
627  || GetCurLib() != unsavedLibraries[0] || !firstRun )
628  {
629  bool accepted;
630 
631  std::tie( accepted, libIdxs ) = SelectMultipleOptions( this, _( "Save Libraries" ),
632  firstRun ? _( "Select libraries to save" )
633  : _( "Some libraries could not be saved to their original files.\n\n"
634  "Do you want to save them to a new file?" ),
635  unsavedLibraries, true );
636 
637  if( !accepted )
638  return false; // dialog has been cancelled
639  }
640 
641  else if( unsavedLibraries.Count() == 1 || GetCurLib() == unsavedLibraries[0] )
642  {
643  // Save just current library, no questions asked
644  libIdxs.push_back( 0 );
645  }
646 
647  for( auto libIndex : libIdxs )
648  allSaved &= saveLibrary( unsavedLibraries[libIndex], !firstRun );
649 
650  firstRun = false;
651  }
652 
653  return true;
654 }
655 
656 
658 {
659  LIB_ALIAS* alias;
660  LIB_PART* part = GetCurPart();
661 
662  ClearMsgPanel();
663 
664  if( !part )
665  return;
666 
667  wxString msg = part->GetName();
668 
669  AppendMsgPanel( _( "Name" ), msg, BLUE, 8 );
670 
671  if( m_aliasName == part->GetName() )
672  msg = _( "None" );
673  else
674  msg = m_aliasName;
675 
676  alias = part->GetAlias( m_aliasName );
677 
678  wxCHECK_RET( alias != NULL, "Alias not found in symbol." );
679 
680  AppendMsgPanel( _( "Alias" ), msg, RED, 8 );
681 
682  static wxChar UnitLetter[] = wxT( "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
683  msg = UnitLetter[m_unit];
684 
685  AppendMsgPanel( _( "Unit" ), msg, BROWN, 8 );
686 
687  if( m_convert > 1 )
688  msg = _( "Convert" );
689  else
690  msg = _( "Normal" );
691 
692  AppendMsgPanel( _( "Body" ), msg, GREEN, 8 );
693 
694  if( part->IsPower() )
695  msg = _( "Power Symbol" );
696  else
697  msg = _( "Symbol" );
698 
699  AppendMsgPanel( _( "Type" ), msg, MAGENTA, 8 );
700  AppendMsgPanel( _( "Description" ), alias->GetDescription(), CYAN, 8 );
701  AppendMsgPanel( _( "Key words" ), alias->GetKeyWords(), DARKDARKGRAY );
702  AppendMsgPanel( _( "Datasheet" ), alias->GetDocFileName(), DARKDARKGRAY );
703 }
Definition: colors.h:57
bool UnitsLocked() const
Check whether part units are interchangeable.
LIB_FIELD * GetField(int aId)
Return pointer to the requested field.
bool saveAllLibraries(bool aClosing)
Definition: libedit.cpp:597
const wxString GetUniStringLibItemName() const
Definition: lib_id.h:125
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
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:104
Class PROJECT holds project specific data.
Definition: project.h:56
int GetPinNameOffset()
static int m_convert
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:199
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:272
This file is part of the common library.
bool RemovePart(const wxString &aName, const wxString &aLibrary)
Removes the part from the part buffer.
bool m_syncPinEdit
Set to true to not synchronize pins at the same position when editing symbols with multiple units or ...
void SetScreen(BASE_SCREEN *aScreen)
Definition: draw_frame.h:167
Definition: colors.h:61
bool isCurrentPart(const LIB_ID &aLibId) const
Returns true if aLibId is an alias for the editor screen part.
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:221
LIB_MANAGER * m_libMgr
manager taking care of temporary modificatoins
void SelectActiveLibrary(const wxString &aLibrary=wxEmptyString)
Set the current active library to aLibrary.
Definition: libedit.cpp:79
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:356
bool IsWritable(const wxFileName &aFileName)
Function IsWritable checks if aFileName can be written.
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:440
void UpdateAliasSelectList()
Field Reference of part, i.e. "IC21".
void OnSavePart(wxCommandEvent &aEvent)
Saves a single part in the selected library.
Definition: libedit.cpp:359
void SetShowDeMorgan(bool show)
This file contains miscellaneous commonly used macros and functions.
std::pair< bool, wxArrayInt > 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:349
void DisplayLibInfos()
Updates the main window title bar with the current library name and read only status of the library...
Definition: libedit.cpp:58
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:102
void SetName(const wxString &aName)
Subclass of DIALOG_LIB_NEW_COMPONENT, which is generated by wxFormBuilder.
LIB_PART * GetCurPart() const
Return the current part being edited or NULL if none selected.
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:511
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:502
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)
LIB_ID RevertPart(const wxString &aAlias, const wxString &aLibrary)
Reverts unsaved changes for a particular part.
void SetUnitCount(int count)
Set the units per part count.
void OnPasteDuplicatePart(wxCommandEvent &aEvent)
Definition: libedit.cpp:412
bool IsMouseCaptured() const
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
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
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:370
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
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:249
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:657
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:106
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
Definition: draw_frame.cpp:812
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:464
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:83
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
static int m_unit
const wxString & GetName() const
const char * name
Definition: DXF_plotter.cpp:61
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.
void OnEditPart(wxCommandEvent &aEvent)
Opens the selected part for editing.
Definition: libedit.cpp:351
void OnCopyCutPart(wxCommandEvent &aEvent)
Definition: libedit.cpp:389
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 wxString LastVisitedPath(const wxString &aSubPathToSearch=wxEmptyString)
Function LastVisitedPath is a quirky function inherited from old code that seems to serve particular ...
size_t i
Definition: json11.cpp:597
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Returns true if library exists.
const wxString & GetName() const
virtual void SetName(const wxString &aName)
Definition of class LIB_EDIT_FRAME.
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:694
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:93
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:101
bool m_drawSpecificUnit
Specify which component parts the current draw item applies to.
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:185
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:233
void UpdatePartSelectList()
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:823
bool GetShowElectricalType()
void loadPart(const wxString &aLibrary, const wxString &aPart, int Unit)
Definition: libedit.cpp:483
CMP_TREE_PANE * m_treePane
component search tree widget
void LockUnits(bool aLockUnits)
Set interchangeable the property for part units.
bool RevertLibrary(const wxString &aLibrary)
Reverts unsaved changes for a particular library.
void SetNormal()
Definition: colors.h:62