KiCad PCB EDA Suite
eeschema/files-io.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) 2013 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 2013 CERN (www.cern.ch)
7  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #include <fctsys.h>
28 #include <sch_draw_panel.h>
29 #include <confirm.h>
30 #include <gestfich.h>
31 #include <sch_edit_frame.h>
32 #include <pgm_base.h>
33 #include <kiface_i.h>
34 #include <richio.h>
35 #include <trace_helpers.h>
36 #include <tool/tool_manager.h>
37 #include <eeschema_id.h>
38 #include <class_library.h>
39 #include <lib_edit_frame.h>
40 #include <sch_sheet.h>
41 #include <sch_sheet_path.h>
42 #include <sch_component.h>
44 #include <project_rescue.h>
45 #include <eeschema_config.h>
46 #include <sch_legacy_plugin.h>
47 #include <sch_eagle_plugin.h>
48 #include <symbol_lib_table.h>
49 #include <dialog_symbol_remap.h>
50 #include <dialog_migrate_buses.h>
51 #include <ws_data_model.h>
52 #include <connection_graph.h>
53 #include <tool/actions.h>
54 
55 bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, bool aSaveUnderNewName,
56  bool aCreateBackupFile )
57 {
58  wxString msg;
59  wxFileName schematicFileName;
60  bool success;
61 
62  if( aScreen == NULL )
63  aScreen = GetScreen();
64 
65  // If no name exists in the window yet - save as new.
66  if( aScreen->GetFileName().IsEmpty() )
67  aSaveUnderNewName = true;
68 
69  // Construct the name of the file to be saved
70  schematicFileName = Prj().AbsolutePath( aScreen->GetFileName() );
71 
72  if( aSaveUnderNewName )
73  {
74  wxFileDialog dlg( this, _( "Schematic Files" ), wxPathOnly( Prj().GetProjectFullName() ),
75  schematicFileName.GetFullName(), SchematicFileWildcard(),
76  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
77 
78  if( dlg.ShowModal() == wxID_CANCEL )
79  return false;
80 
81  schematicFileName = dlg.GetPath();
82 
83  if( schematicFileName.GetExt() != SchematicFileExtension )
84  schematicFileName.SetExt( SchematicFileExtension );
85  }
86 
87  if( !IsWritable( schematicFileName ) )
88  return false;
89 
90  // Create backup if requested
91  if( aCreateBackupFile && schematicFileName.FileExists() )
92  {
93  wxFileName backupFileName = schematicFileName;
94 
95  // Rename the old file to a '-bak' suffixed one:
96  backupFileName.SetExt( schematicFileName.GetExt() + GetBackupSuffix() );
97 
98  if( backupFileName.FileExists() )
99  wxRemoveFile( backupFileName.GetFullPath() );
100 
101  if( !wxRenameFile( schematicFileName.GetFullPath(), backupFileName.GetFullPath() ) )
102  {
103  msg.Printf( _( "Could not save backup of file \"%s\"" ),
104  GetChars( schematicFileName.GetFullPath() ) );
105  DisplayError( this, msg );
106  }
107  }
108 
109  // Save
110  wxLogTrace( traceAutoSave,
111  wxT( "Saving file <" ) + schematicFileName.GetFullPath() + wxT( ">" ) );
112 
113  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
114 
115  try
116  {
117  pi->Save( schematicFileName.GetFullPath(), aScreen, &Kiway() );
118  success = true;
119  }
120  catch( const IO_ERROR& ioe )
121  {
122  msg.Printf( _( "Error saving schematic file \"%s\".\n%s" ),
123  GetChars( schematicFileName.GetFullPath() ), GetChars( ioe.What() ) );
124  DisplayError( this, msg );
125 
126  msg.Printf( _( "Failed to save \"%s\"" ), GetChars( schematicFileName.GetFullPath() ) );
127  AppendMsgPanel( wxEmptyString, msg, CYAN );
128 
129  success = false;
130  }
131 
132  if( success )
133  {
134  // Delete auto save file.
135  wxFileName autoSaveFileName = schematicFileName;
136  autoSaveFileName.SetName( GetAutoSaveFilePrefix() + schematicFileName.GetName() );
137 
138  if( autoSaveFileName.FileExists() )
139  {
140  wxLogTrace( traceAutoSave,
141  wxT( "Removing auto save file <" ) + autoSaveFileName.GetFullPath() +
142  wxT( ">" ) );
143 
144  wxRemoveFile( autoSaveFileName.GetFullPath() );
145  }
146 
147  // Update the screen and frame info and reset the lock file.
148  if( aSaveUnderNewName )
149  {
150  aScreen->SetFileName( schematicFileName.GetFullPath() );
151  LockFile( schematicFileName.GetFullPath() );
152  }
153 
154  aScreen->ClrSave();
155  aScreen->ClrModify();
156 
157  msg.Printf( _( "File %s saved" ), GetChars( aScreen->GetFileName() ) );
158  SetStatusText( msg, 0 );
159  }
160  else
161  {
162  DisplayError( this, _( "File write operation failed." ) );
163  }
164 
165  return success;
166 }
167 
168 
169 void SCH_EDIT_FRAME::Save_File( bool doSaveAs )
170 {
171  if( doSaveAs )
172  {
173  if( SaveEEFile( NULL, true ) )
175  }
176  else
177  {
178  SaveEEFile( NULL );
179  }
180 
181  UpdateTitle();
182 }
183 
184 
185 bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
186 {
187  // implement the pseudo code from KIWAY_PLAYER.h:
188 
189  // This is for python:
190  if( aFileSet.size() != 1 )
191  {
192  UTF8 msg = StrPrintf( "Eeschema:%s() takes only a single filename.", __func__ );
193  DisplayError( this, msg );
194  return false;
195  }
196 
197  wxString fullFileName( aFileSet[0] );
198 
199  // We insist on caller sending us an absolute path, if it does not, we say it's a bug.
200  wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(), wxT( "Path is not absolute!" ) );
201 
202  if( !LockFile( fullFileName ) )
203  {
204  wxString msg = wxString::Format( _( "Schematic file \"%s\" is already open." ),
205  fullFileName );
206  DisplayError( this, msg );
207  return false;
208  }
209 
210  if( !AskToSaveChanges() )
211  return false;
212 
213  wxFileName pro = fullFileName;
214  pro.SetExt( ProjectFileExtension );
215 
216  bool is_new = !wxFileName::IsFileReadable( fullFileName );
217 
218  // If its a non-existent schematic and caller thinks it exists
219  if( is_new && !( aCtl & KICTL_CREATE ) )
220  {
221  // notify user that fullFileName does not exist, ask if user wants to create it.
222  wxString ask = wxString::Format( _( "Schematic \"%s\" does not exist. Do you wish to create it?" ),
223  fullFileName );
224  if( !IsOK( this, ask ) )
225  return false;
226  }
227 
228  // unload current project file before loading new
229  {
230  SetScreen( nullptr );
231  delete g_RootSheet;
232  if( g_CurrentSheet )
234  g_RootSheet = nullptr;
235 
236  CreateScreens();
237  }
238 
239  GetScreen()->SetFileName( fullFileName );
240  g_RootSheet->SetFileName( fullFileName );
241 
242  SetStatusText( wxEmptyString );
243  ClearMsgPanel();
244 
245  // PROJECT::SetProjectFullName() is an impactful function. It should only be
246  // called under carefully considered circumstances.
247 
248  // The calling code should know not to ask me here to change projects unless
249  // it knows what consequences that will have on other KIFACEs running and using
250  // this same PROJECT. It can be very harmful if that calling code is stupid.
251 
252  // Don't reload the symbol libraries if we are just launching Eeschema from KiCad again.
253  // They are already saved in the kiface project object.
254  if( pro.GetFullPath() != Prj().GetProjectFullName()
256  {
257  Prj().SetProjectFullName( pro.GetFullPath() );
258 
259  // load the libraries here, not in SCH_SCREEN::Draw() which is a context
260  // that will not tolerate DisplayError() dialog since we're already in an
261  // event handler in there.
262  // And when a schematic file is loaded, we need these libs to initialize
263  // some parameters (links to PART LIB, dangling ends ...)
265  Prj().SchLibs();
266  }
267 
268  LoadProjectFile();
269 
270  // Load the symbol library table, this will be used forever more.
272  Prj().SchSymbolLibTable();
273 
274  if( is_new )
275  {
276  // mark new, unsaved file as modified.
277  GetScreen()->SetModify();
278  }
279  else
280  {
281  SetScreen( nullptr );
282  delete g_RootSheet; // Delete the current project.
283  g_RootSheet = NULL; // Force CreateScreens() to build new empty project on load failure.
284 
285  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
286 
287  // This will rename the file if there is an autosave and the user want to recover
288  CheckForAutoSaveFile( fullFileName );
289 
290  try
291  {
292  g_RootSheet = pi->Load( fullFileName, &Kiway() );
293 
297 
298  if( !pi->GetError().IsEmpty() )
299  {
300  DisplayErrorMessage( this,
301  _( "The entire schematic could not be loaded. Errors "
302  "occurred attempting to load \nhierarchical sheet "
303  "schematics." ),
304  pi->GetError() );
305  }
306  }
307  catch( const IO_ERROR& ioe )
308  {
309  // Do not leave g_RootSheet == NULL because it is expected to be
310  // a valid sheet. Therefore create a dummy empty root sheet and screen.
311  CreateScreens();
313 
314  wxString msg;
315  msg.Printf( _( "Error loading schematic file \"%s\".\n%s" ),
316  GetChars( fullFileName ), GetChars( ioe.What() ) );
317  DisplayError( this, msg );
318 
319  msg.Printf( _( "Failed to load \"%s\"" ), GetChars( fullFileName ) );
320  AppendMsgPanel( wxEmptyString, msg, CYAN );
321 
322  return false;
323  }
324 
325  // It's possible the schematic parser fixed errors due to bugs so warn the user
326  // that the schematic has been fixed (modified).
327  SCH_SHEET_LIST sheetList( g_RootSheet );
328 
329  if( sheetList.IsModified() )
330  {
331  DisplayInfoMessage( this,
332  _( "An error was found when loading the schematic that has "
333  "been automatically fixed. Please save the schematic to "
334  "repair the broken file or it may not be usable with other "
335  "versions of KiCad." ) );
336  }
337 
338  UpdateFileHistory( fullFileName );
339 
340  SCH_SCREENS schematic;
341 
342  // Convert old projects over to use symbol library table.
343  if( schematic.HasNoFullyDefinedLibIds() )
344  {
345  DIALOG_SYMBOL_REMAP dlgRemap( this );
346 
347  dlgRemap.ShowQuasiModal();
348  }
349  else
350  {
351  // Double check to ensure no legacy library list entries have been
352  // added to the projec file symbol library list.
353  wxString paths;
354  wxArrayString libNames;
355 
356  PART_LIBS::LibNamesAndPaths( &Prj(), false, &paths, &libNames );
357 
358  if( !libNames.IsEmpty() )
359  {
361  {
362  wxRichMessageDialog invalidLibDlg(
363  this,
364  _( "Illegal entry found in project file symbol library list." ),
365  _( "Project Load Warning" ),
366  wxOK | wxCENTER | wxICON_EXCLAMATION );
367  invalidLibDlg.SetExtendedMessage(
368  _( "Symbol libraries defined in the project file symbol library list "
369  "are no longer supported and will be\nremoved. This may cause "
370  "broken symbol library links under certain conditions." ) );
371  invalidLibDlg.ShowCheckBox( _( "Do not show this dialog again." ) );
372  invalidLibDlg.ShowModal();
373  m_showIllegalSymbolLibDialog = !invalidLibDlg.IsCheckBoxChecked();
374  }
375 
376  libNames.Clear();
377  paths.Clear();
378  PART_LIBS::LibNamesAndPaths( &Prj(), true, &paths, &libNames );
379  }
380 
381  // Check to see whether some old library parts need to be rescued
382  // Only do this if RescueNeverShow was not set.
383  wxConfigBase *config = Kiface().KifaceSettings();
384  bool rescueNeverShow = false;
385  config->Read( RescueNeverShowEntry, &rescueNeverShow, false );
386 
387  if( !rescueNeverShow )
389  }
390 
391  schematic.UpdateSymbolLinks(); // Update all symbol library links for all sheets.
393 
394  // Ensure the schematic is fully segmented on first display
396  GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 );
397 
398  GetScreen()->TestDanglingEnds(); // Only perform the dangling end test on root sheet.
399 
400  // Migrate conflicting bus definitions
401  // TODO(JE) This should only run once based on schematic file version
402  if( g_ConnectionGraph->GetBusesNeedingMigration().size() > 0 )
403  {
404  DIALOG_MIGRATE_BUSES dlg( this );
405  dlg.ShowQuasiModal();
406 
408  OnModify();
409  }
410 
411  GetScreen()->m_Initialized = true;
412  }
413 
417 
418  // re-create junctions if needed. Eeschema optimizes wires by merging
419  // colinear segments. If a schematic is saved without a valid
420  // cache library or missing installed libraries, this can cause connectivity errors
421  // unless junctions are added.
422  FixupJunctions();
423 
424  SyncView();
426 
427  UpdateTitle();
428 
429  return true;
430 }
431 
432 
434 {
435  wxString fullFileName;
436  SCH_SCREEN* screen = GetScreen();
437 
438  if( !screen )
439  {
440  wxLogError( wxT( "Document not ready, cannot import" ) );
441  return false;
442  }
443 
444  // open file chooser dialog
445  wxString path = wxPathOnly( Prj().GetProjectFullName() );
446 
447  wxFileDialog dlg( this, _( "Append Schematic" ), path, wxEmptyString,
448  SchematicFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
449 
450  if( dlg.ShowModal() == wxID_CANCEL )
451  return false;
452 
453  fullFileName = dlg.GetPath();
454 
455  if( !LoadSheetFromFile( GetCurrentSheet().Last(), &GetCurrentSheet(), fullFileName ) )
456  return false;
457 
458  SCH_SCREENS screens( GetCurrentSheet().Last() );
459  screens.TestDanglingEnds();
460 
464 
465  SyncView();
466  HardRedraw(); // Full reinit of the current screen and the display.
467  OnModify();
468 
469  return true;
470 }
471 
472 
473 void SCH_EDIT_FRAME::OnAppendProject( wxCommandEvent& event )
474 {
475  if( GetScreen() && GetScreen()->IsModified() )
476  {
477  wxString msg = _( "This operation cannot be undone.\n\n"
478  "Do you want to save the current document before proceeding?" );
479 
480  if( IsOK( this, msg ) )
481  SaveProject();
482  }
483 
484  AppendSchematic();
485 }
486 
487 
488 void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent )
489 {
490  if( !AskToSaveChanges() )
491  return;
492 
493  // Set the project location if none is set
494  bool setProject = Prj().GetProjectFullName().IsEmpty();
495  wxString path = wxPathOnly( Prj().GetProjectFullName() );
496 
497  wxFileDialog dlg( this, _( "Import Schematic" ), path, wxEmptyString,
498  EagleSchematicFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
499 
500  if( dlg.ShowModal() == wxID_CANCEL )
501  return;
502 
503  if( setProject )
504  {
505  wxFileName projectFn( dlg.GetPath() );
506  projectFn.SetExt( ProjectFileExtension );
507  Prj().SetProjectFullName( projectFn.GetFullPath() );
508  }
509 
510  // For now there is only one import plugin
511  importFile( dlg.GetPath(), SCH_IO_MGR::SCH_EAGLE );
512 }
513 
514 
516 {
517  SCH_SCREEN* screen;
518  SCH_SCREENS screenList;
519  bool success = true;
520 
521  // I want to see it in the debugger, show me the string! Can't do that with wxFileName.
522  wxString fileName = Prj().AbsolutePath( g_RootSheet->GetFileName() );
523  wxFileName fn = fileName;
524 
525  if( !fn.IsDirWritable() )
526  {
527  wxString msg = wxString::Format( _( "Directory \"%s\" is not writable." ), fn.GetPath() );
528  DisplayError( this, msg );
529  return false;
530  }
531 
532  for( screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
533  success &= SaveEEFile( screen );
534 
536 
537  UpdateTitle();
538 
539  return success;
540 }
541 
542 
544 {
545  wxFileName tmpFileName = g_RootSheet->GetFileName();
546  wxFileName fn = tmpFileName;
547  wxFileName tmp;
548  SCH_SCREENS screens;
549 
550  bool autoSaveOk = true;
551 
552  tmp.AssignDir( fn.GetPath() );
553 
554  if( !tmp.IsOk() )
555  return false;
556 
557  if( !IsWritable( tmp ) )
558  return false;
559 
560  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
561  {
562  // Only create auto save files for the schematics that have been modified.
563  if( !screen->IsSave() )
564  continue;
565 
566  tmpFileName = fn = screen->GetFileName();
567 
568  // Auto save file name is the normal file name prefixed with GetAutoSavePrefix().
569  fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() );
570 
571  screen->SetFileName( fn.GetFullPath() );
572 
573  if( SaveEEFile( screen, false, NO_BACKUP_FILE ) )
574  screen->SetModify();
575  else
576  autoSaveOk = false;
577 
578  screen->SetFileName( tmpFileName.GetFullPath() );
579  }
580 
581  if( autoSaveOk )
582  m_autoSaveState = false;
583 
584  return autoSaveOk;
585 }
586 
587 
588 bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType )
589 {
590  wxString projectpath;
591  wxFileName newfilename;
592  SCH_SHEET_LIST sheetList( g_RootSheet );
593 
594  switch( (SCH_IO_MGR::SCH_FILE_T) aFileType )
595  {
596  case SCH_IO_MGR::SCH_EAGLE:
597  // We insist on caller sending us an absolute path, if it does not, we say it's a bug.
598  wxASSERT_MSG( wxFileName( aFileName ).IsAbsolute(),
599  wxT( "Import eagle schematic caller didn't send full filename" ) );
600 
601  if( !LockFile( aFileName ) )
602  {
603  wxString msg = wxString::Format( _( "Schematic file \"%s\" is already open." ),
604  aFileName );
605  DisplayError( this, msg );
606  return false;
607  }
608 
609  try
610  {
611  delete g_RootSheet;
612  g_RootSheet = nullptr;
613  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ) );
614  g_RootSheet = pi->Load( aFileName, &Kiway() );
615 
616  // Eagle sheets do not use a worksheet frame by default, so set it to an empty one
618  pglayout.SetEmptyLayout();
619 
620  BASE_SCREEN::m_PageLayoutDescrFileName = "empty.kicad_wks";
621  wxFileName layoutfn( Kiway().Prj().GetProjectPath(),
623  wxFile layoutfile;
624 
625  if( layoutfile.Create( layoutfn.GetFullPath() ) )
626  {
627  layoutfile.Write( WS_DATA_MODEL::EmptyLayout() );
628  layoutfile.Close();
629  }
630 
631  projectpath = Kiway().Prj().GetProjectPath();
632  newfilename.SetPath( Prj().GetProjectPath() );
633  newfilename.SetName( Prj().GetProjectName() );
634  newfilename.SetExt( SchematicFileExtension );
635 
639 
640  g_RootSheet->SetFileName( newfilename.GetFullPath() );
641  GetScreen()->SetFileName( newfilename.GetFullPath() );
642  GetScreen()->SetModify();
643  SaveProjectSettings( false );
644 
645  UpdateFileHistory( aFileName );
646  SCH_SCREENS schematic;
647  schematic.UpdateSymbolLinks(); // Update all symbol library links for all sheets.
648 
649  // Ensure the schematic is fully segmented on first display
651 
652  GetScreen()->m_Initialized = true;
653 
654  EE_TYPE_COLLECTOR components;
655  SCH_SCREENS allScreens;
656 
657  for( SCH_SCREEN* screen = allScreens.GetFirst(); screen; screen = allScreens.GetNext() )
658  {
659  components.Collect( screen->GetDrawItems(), EE_COLLECTOR::ComponentsOnly );
660 
661  for( int cmpIdx = 0; cmpIdx < components.GetCount(); ++cmpIdx )
662  {
663  std::vector<wxPoint> pts;
664  SCH_COMPONENT* cmp = static_cast<SCH_COMPONENT*>( components[cmpIdx] );
665 
666  // Update footprint LIB_ID to point to the imported Eagle library
667  auto fpField = cmp->GetField( FOOTPRINT );
668 
669  if( !fpField->GetText().IsEmpty() )
670  {
671  LIB_ID fpId;
672  fpId.Parse( fpField->GetText(), LIB_ID::ID_SCH, true );
673  fpId.SetLibNickname( newfilename.GetName() );
674  fpField->SetText( fpId.Format() );
675  }
676  }
677  }
678 
679  GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 );
680  // Only perform the dangling end test on root sheet.
683 
687  SyncView();
688  UpdateTitle();
689  }
690  catch( const IO_ERROR& ioe )
691  {
692  // Do not leave g_RootSheet == NULL because it is expected to be
693  // a valid sheet. Therefore create a dummy empty root sheet and screen.
694  CreateScreens();
696 
697  wxString msg;
698  msg.Printf( _( "Error loading schematic \"%s\".\n%s" ), aFileName, ioe.What() );
699  DisplayError( this, msg );
700 
701  msg.Printf( _( "Failed to load \"%s\"" ), aFileName );
702  AppendMsgPanel( wxEmptyString, msg, CYAN );
703 
704  return false;
705  }
706 
707  return true;
708 
709  default:
710  return false;
711  }
712 }
713 
714 
716 {
717  SCH_SCREENS screenList;
718 
719  // Save any currently open and modified project files.
720  for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
721  {
722  if( screen->IsModify() )
723  {
724  if( !HandleUnsavedChanges( this, _( "The current schematic has been modified. "
725  "Save changes?" ),
726  [&]()->bool { return SaveProject(); } ) )
727  {
728  return false;
729  }
730  }
731  }
732 
733  return true;
734 }
WS_DATA_MODEL handles the graphic items list to draw/plot the frame and title block.
Definition: ws_data_model.h:39
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
Class SCH_SHEET_LIST.
void Collect(EDA_ITEM *aItem, const KICAD_T aScanList[])
Function Collect scans a DLIST using this class's Inspector method, which does the collection.
void Save_File(bool doSaveAs=false)
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
Definition: confirm.cpp:208
bool IsModified()
Function IsModified checks the entire hierarchy for any modifications.
const wxString & GetFileName() const
Definition: sch_screen.h:118
SCH_SCREEN * GetNext()
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Function OpenProjectFiles is abstract, and opens a project or set of files given by aFileList.
wxString SchematicFileWildcard()
static void LibNamesAndPaths(PROJECT *aProject, bool doSave, wxString *aPaths, wxArrayString *aNames=NULL)
Save or load the names of the currently configured part libraries (without paths).
int StrPrintf(std::string *aResult, const char *aFormat,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:258
This file is part of the common library TODO brief description.
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
This file is part of the common library.
void SetFileName(const wxString &aFilename)
Definition: sch_sheet.h:457
const std::string ProjectFileExtension
void SetScreen(BASE_SCREEN *aScreen) override
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:163
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
#define KICTL_CREATE
caller thinks requested project files may not exist
Definition: kiway_player.h:79
bool AskToSaveChanges()
Checks if any of the screens has unsaved changes and asks the user whether to save or drop them.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
static TOOL_ACTION zoomFitScreen
Definition: actions.h:92
const wxChar RescueNeverShowEntry[]
void UpdateTitle()
Set the main window title bar text.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
void OnAppendProject(wxCommandEvent &event)
virtual wxConfigBase * config()
Returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
static const KICAD_T ComponentsOnly[]
Definition: ee_collectors.h:44
VTBL_ENTRY _ELEM * GetElem(ELEM_T aIndex)
Typically wrapped somewhere else in a more meaningful function wrapper.
Definition: project.cpp:205
static wxString EmptyLayout()
Returns a string containing the empty layout shape.
bool IsWritable(const wxFileName &aFileName)
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
#define NO_BACKUP_FILE
CONNECTION_GRAPH * g_ConnectionGraph
This also wants to live in the eventual SCHEMATIC object.
bool importFile(const wxString &aFileName, int aFileType)
Load the given filename but sets the path to the current project path.
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
Field Name Module PCB, i.e. "16DIP300".
void UpdateFileHistory(const wxString &FullFileName, wxFileHistory *aFileHistory=NULL)
Update the list of recently opened files.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:51
void SaveProjectSettings(bool aAskForSave) override
Save changes to the project settings to the project (.pro) file.
VTBL_ENTRY const wxString AbsolutePath(const wxString &aFileName) const
Function AbsolutePath fixes up aFileName if it is relative to the project's directory to be an absolu...
Definition: project.cpp:385
static WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
void OnImportProject(wxCommandEvent &event)
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:217
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
Definition: base_screen.h:109
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:113
bool LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, const wxString &aFileName)
Load a the KiCad schematic file aFileName into the sheet aSheet.
Definition: sheet.cpp:102
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47
void CheckForAutoSaveFile(const wxFileName &aFileName)
Check if an auto save file exists for aFileName and takes the appropriate action depending on the use...
SCH_SHEET_PATH * g_CurrentSheet
With the new connectivity algorithm, many more places than before want to know what the current sheet...
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
static wxString GetBackupSuffix()
void HardRedraw() override
Rebuild the GAL and redraw the screen.
void SyncView()
Mark all items for refresh.
bool m_Initialized
Definition: base_screen.h:129
int ShowQuasiModal()
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
const std::string SchematicFileExtension
SCH_SHEET_PATH & GetCurrentSheet()
Definition: colors.h:59
Definition of file extensions used in Kicad.
bool AppendSchematic()
Import a KiCad schematic into the current sheet.
bool SaveEEFile(SCH_SCREEN *aScreen, bool aSaveUnderNewName=false, bool aCreateBackupFile=CREATE_BACKUP_FILE)
Save aScreen to a schematic file.
bool CreateArchiveLibraryCacheFile(bool aUseCurrentSheetFilename=false)
Create a symbol library file with the name of the root document plus the '-cache' suffix,...
Definition: libarch.cpp:42
wxLogTrace helper definitions.
bool LoadProjectFile()
Loads the KiCad project file (*.pro) settings specific to Eeschema.
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
Class SCH_SHEET_PATH.
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96
virtual void ClearMsgPanel()
Clear all messages from the message panel.
VTBL_ENTRY void SetProjectFullName(const wxString &aFullPathAndName)
Function SetProjectFullName sets the: 1) full directory, 2) basename, and 3) extension of the project...
Definition: project.cpp:64
#define _(s)
void clear()
Forwarded method from std::vector.
UTF8 Format() const
Definition: lib_id.cpp:237
bool m_showIllegalSymbolLibDialog
bool doAutoSave() override
Save the schematic files that have been modified and not yet saved.
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:629
static wxString GetAutoSaveFilePrefix()
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:520
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
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:101
see class PGM_BASE
void UpdateSymbolLinks(bool aForce=false)
Initialize or reinitialize the weak reference to the LIB_PART for each SCH_COMPONENT found in the ful...
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
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
wxString EagleSchematicFileWildcard()
Class EE_TYPE_COLLECTOR merely gathers up all SCH_ITEMs of a given set of KICAD_T type(s).
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
Definition: sch_screen.cpp:781
void ClrModify()
Definition: base_screen.h:225
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
bool RescueSymbolLibTableProject(bool aRunningOnDemand)
SCH_SCREEN * GetFirst()
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
TOOL_MANAGER * m_toolManager
void ClearDrawingState()
Clear the state flags of all the items in the screen.
Definition: sch_screen.cpp:613
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Free the undo or redo list from aList element.
Definition: sch_screen.cpp:598
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:116
Definition for part library class.
void SetModify()
Definition: base_screen.h:224
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:276
std::vector< const CONNECTION_SUBGRAPH * > GetBusesNeedingMigration()
Determines which subgraphs have more than one conflicting bus label.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:243
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:294
void ClrSave()
Definition: base_screen.h:227
void RecalculateConnections(bool aDoCleanup=true)
Generates the connection data for the entire schematic hierarchy.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:486
SCH_SCREEN * LastScreen() const
Function LastScreen.
void NormalizeSchematicOnFirstLoad(bool recalculateConnections)
Perform all cleanup and normalization steps so that the whole schematic is in a good state.
bool LockFile(const wxString &aFileName)
Mark a schematic file as being in use.