2011-10-15 13:25:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-05-07 18:32:06 +00:00
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-10-22 00:48:25 +00:00
|
|
|
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
|
2013-01-24 17:46:37 +00:00
|
|
|
* Copyright (C) 2013 CERN (www.cern.ch)
|
2020-03-16 13:04:50 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-15 13:25:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <advanced_config.h>
|
|
|
|
#include <class_library.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <connection_graph.h>
|
|
|
|
#include <dialog_migrate_buses.h>
|
|
|
|
#include <dialog_symbol_remap.h>
|
|
|
|
#include <eeschema_settings.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gestfich.h>
|
2020-01-03 16:04:54 +00:00
|
|
|
#include <id.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <kiface_i.h>
|
|
|
|
#include <kiplatform/app.h>
|
|
|
|
#include <pgm_base.h>
|
2020-07-09 21:57:16 +00:00
|
|
|
#include <profile.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <project/project_file.h>
|
2015-06-22 15:38:54 +00:00
|
|
|
#include <project_rescue.h>
|
2020-07-03 13:40:31 +00:00
|
|
|
#include <reporter.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <richio.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_edit_frame.h>
|
2020-10-05 18:38:40 +00:00
|
|
|
#include <sch_plugins/legacy/sch_legacy_plugin.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
#include <schematic.h>
|
|
|
|
#include <settings/common_settings.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2017-09-01 20:42:20 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2019-06-04 12:46:02 +00:00
|
|
|
#include <tool/actions.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2020-05-12 17:40:56 +00:00
|
|
|
#include <tools/sch_editor_control.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <trace_helpers.h>
|
2020-05-20 01:31:47 +00:00
|
|
|
#include <widgets/infobar.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2020-10-14 00:23:36 +00:00
|
|
|
#include <page_layout/ws_data_model.h>
|
2020-12-12 18:11:51 +00:00
|
|
|
#include <wx/ffile.h>
|
2020-10-22 00:55:43 +00:00
|
|
|
#include <wx/stdpaths.h>
|
2020-11-03 19:24:05 +00:00
|
|
|
#include <tools/ee_inspection_tool.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2020-06-20 01:06:52 +00:00
|
|
|
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2013-02-13 17:18:23 +00:00
|
|
|
wxFileName schematicFileName;
|
|
|
|
bool success;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
if( aSheet == NULL )
|
|
|
|
aSheet = GetCurrentSheet().Last();
|
|
|
|
|
|
|
|
SCH_SCREEN* screen = aSheet->GetScreen();
|
|
|
|
|
|
|
|
wxCHECK( screen, false );
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2013-05-07 18:32:06 +00:00
|
|
|
// If no name exists in the window yet - save as new.
|
2020-04-26 20:53:29 +00:00
|
|
|
if( screen->GetFileName().IsEmpty() )
|
2012-09-28 17:47:41 +00:00
|
|
|
aSaveUnderNewName = true;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2013-05-07 18:32:06 +00:00
|
|
|
// Construct the name of the file to be saved
|
2020-04-26 20:53:29 +00:00
|
|
|
schematicFileName = Prj().AbsolutePath( screen->GetFileName() );
|
2013-02-13 17:18:23 +00:00
|
|
|
|
|
|
|
if( aSaveUnderNewName )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
2020-10-22 00:55:43 +00:00
|
|
|
wxFileName savePath( Prj().GetProjectFullName() );
|
2020-03-16 13:04:50 +00:00
|
|
|
|
2020-10-22 00:55:43 +00:00
|
|
|
if( !savePath.IsOk() || !savePath.IsDirWritable() )
|
|
|
|
{
|
|
|
|
savePath = GetMruPath();
|
|
|
|
|
|
|
|
if( !savePath.IsOk() || !savePath.IsDirWritable() )
|
|
|
|
savePath = wxStandardPaths::Get().GetDocumentsDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFileDialog dlg( this, _( "Schematic Files" ), savePath.GetPath(),
|
|
|
|
schematicFileName.GetFullName(), KiCadSchematicFileWildcard(),
|
2016-07-11 19:48:46 +00:00
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2013-02-13 17:18:23 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
schematicFileName = dlg.GetPath();
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2020-05-15 13:25:11 +00:00
|
|
|
if( schematicFileName.GetExt().IsEmpty() )
|
2020-03-16 13:04:50 +00:00
|
|
|
schematicFileName.SetExt( KiCadSchematicFileExtension );
|
2013-02-13 17:18:23 +00:00
|
|
|
}
|
2011-08-18 19:25:12 +00:00
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
if( !IsWritable( schematicFileName ) )
|
|
|
|
return false;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2020-06-19 23:31:26 +00:00
|
|
|
wxFileName tempFile( schematicFileName );
|
|
|
|
tempFile.SetName( wxT( "." ) + tempFile.GetName() );
|
|
|
|
tempFile.SetExt( tempFile.GetExt() + wxT( "$" ) );
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// Save
|
2011-10-15 13:25:57 +00:00
|
|
|
wxLogTrace( traceAutoSave,
|
|
|
|
wxT( "Saving file <" ) + schematicFileName.GetFullPath() + wxT( ">" ) );
|
|
|
|
|
2020-03-16 13:04:50 +00:00
|
|
|
SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::GuessPluginTypeFromSchPath(
|
|
|
|
schematicFileName.GetFullPath() );
|
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( pluginType ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
try
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
2020-06-19 23:31:26 +00:00
|
|
|
pi->Save( tempFile.GetFullPath(), aSheet, &Schematic() );
|
2017-01-27 15:56:36 +00:00
|
|
|
success = true;
|
2010-10-26 20:25:48 +00:00
|
|
|
}
|
2017-01-27 15:56:36 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Error saving schematic file \"%s\".\n%s" ),
|
2020-04-16 16:43:50 +00:00
|
|
|
schematicFileName.GetFullPath(), ioe.What() );
|
2017-01-27 15:56:36 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
|
2020-06-19 23:31:26 +00:00
|
|
|
msg.Printf( _( "Failed to create temporary file \"%s\"" ), tempFile.GetFullPath() );
|
2020-12-08 05:27:34 +00:00
|
|
|
SetMsgPanel( wxEmptyString, msg );
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2020-06-19 23:31:26 +00:00
|
|
|
// In case we started a file but didn't fully write it, clean up
|
|
|
|
wxRemoveFile( tempFile.GetFullPath() );
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
success = false;
|
|
|
|
}
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2020-06-19 23:31:26 +00:00
|
|
|
if( success )
|
|
|
|
{
|
|
|
|
// Replace the original with the temporary file we just wrote
|
|
|
|
success = wxRenameFile( tempFile.GetFullPath(), schematicFileName.GetFullPath() );
|
|
|
|
|
|
|
|
if( !success )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Error saving schematic file \"%s\".\n"
|
|
|
|
"Failed to rename temporary file %s" ),
|
|
|
|
schematicFileName.GetFullPath(), tempFile.GetFullPath() );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
|
|
|
|
msg.Printf( _( "Failed to rename temporary file \"%s\"" ), tempFile.GetFullPath() );
|
2020-12-08 05:27:34 +00:00
|
|
|
SetMsgPanel( wxEmptyString, msg );
|
2020-06-19 23:31:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
if( success )
|
2011-08-18 19:25:12 +00:00
|
|
|
{
|
2013-02-13 17:18:23 +00:00
|
|
|
// Delete auto save file.
|
2011-10-15 13:25:57 +00:00
|
|
|
wxFileName autoSaveFileName = schematicFileName;
|
2019-03-18 12:22:33 +00:00
|
|
|
autoSaveFileName.SetName( GetAutoSaveFilePrefix() + schematicFileName.GetName() );
|
2011-10-15 13:25:57 +00:00
|
|
|
|
|
|
|
if( autoSaveFileName.FileExists() )
|
|
|
|
{
|
|
|
|
wxLogTrace( traceAutoSave,
|
|
|
|
wxT( "Removing auto save file <" ) + autoSaveFileName.GetFullPath() +
|
|
|
|
wxT( ">" ) );
|
|
|
|
|
|
|
|
wxRemoveFile( autoSaveFileName.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
2018-09-24 12:56:54 +00:00
|
|
|
// Update the screen and frame info and reset the lock file.
|
2013-02-13 17:18:23 +00:00
|
|
|
if( aSaveUnderNewName )
|
2018-09-24 12:56:54 +00:00
|
|
|
{
|
2020-04-26 20:53:29 +00:00
|
|
|
screen->SetFileName( schematicFileName.GetFullPath() );
|
2021-01-06 19:29:18 +00:00
|
|
|
aSheet->SetFileName( schematicFileName.GetFullPath() );
|
2018-09-24 12:56:54 +00:00
|
|
|
LockFile( schematicFileName.GetFullPath() );
|
|
|
|
}
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
screen->ClrSave();
|
|
|
|
screen->ClrModify();
|
2013-02-13 17:18:23 +00:00
|
|
|
|
2020-12-08 23:58:07 +00:00
|
|
|
msg.Printf( _( "File \"%s\" saved." ), screen->GetFileName() );
|
2011-08-18 19:25:12 +00:00
|
|
|
SetStatusText( msg, 0 );
|
2011-02-17 18:34:27 +00:00
|
|
|
}
|
2013-02-13 17:18:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "File write operation failed." ) );
|
|
|
|
}
|
2010-10-26 20:25:48 +00:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-24 23:36:31 +00:00
|
|
|
void SCH_EDIT_FRAME::Save_File( bool doSaveAs )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-05-24 23:36:31 +00:00
|
|
|
if( doSaveAs )
|
2007-09-30 02:37:06 +00:00
|
|
|
{
|
2013-01-21 19:58:02 +00:00
|
|
|
if( SaveEEFile( NULL, true ) )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
|
|
|
|
wxCHECK( screen, /* void */ );
|
|
|
|
|
|
|
|
wxFileName fn = screen->GetFileName();
|
|
|
|
|
|
|
|
if( fn.GetExt() == LegacySchematicFileExtension )
|
|
|
|
CreateArchiveLibraryCacheFile( true );
|
2020-10-06 02:13:06 +00:00
|
|
|
|
|
|
|
// If we are saving under a new name, and don't have a real project yet, create one
|
|
|
|
fn.SetExt( ProjectFileExtension );
|
|
|
|
|
|
|
|
if( fn.IsDirWritable() && !fn.FileExists() )
|
|
|
|
{
|
|
|
|
Prj().SetReadOnly( false );
|
|
|
|
GetSettingsManager()->SaveProjectAs( fn.GetFullPath() );
|
|
|
|
}
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
2019-05-24 23:36:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SaveEEFile( NULL );
|
2007-09-30 02:37:06 +00:00
|
|
|
}
|
2013-02-01 07:58:49 +00:00
|
|
|
|
|
|
|
UpdateTitle();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
|
2013-01-24 17:46:37 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// implement the pseudo code from KIWAY_PLAYER.h:
|
2020-03-25 15:27:15 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// This is for python:
|
|
|
|
if( aFileSet.size() != 1 )
|
2013-01-24 17:46:37 +00:00
|
|
|
{
|
2020-03-25 15:27:15 +00:00
|
|
|
msg.Printf( "Eeschema:%s() takes only a single filename.", __WXFUNCTION__ );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
2013-01-24 17:46:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
wxString fullFileName( aFileSet[0] );
|
2013-01-24 17:46:37 +00:00
|
|
|
|
2018-09-15 21:35:32 +00:00
|
|
|
// We insist on caller sending us an absolute path, if it does not, we say it's a bug.
|
|
|
|
wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(), wxT( "Path is not absolute!" ) );
|
|
|
|
|
2014-09-07 19:01:26 +00:00
|
|
|
if( !LockFile( fullFileName ) )
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
{
|
2020-03-25 15:27:15 +00:00
|
|
|
msg.Printf( _( "Schematic file \"%s\" is already open." ), fullFileName );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-24 17:46:37 +00:00
|
|
|
|
2017-09-20 14:20:38 +00:00
|
|
|
if( !AskToSaveChanges() )
|
|
|
|
return false;
|
2013-01-24 17:46:37 +00:00
|
|
|
|
2020-07-09 21:57:16 +00:00
|
|
|
PROF_COUNTER openFiles( "OpenProjectFile" );
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxFileName pro = fullFileName;
|
2020-05-31 21:42:04 +00:00
|
|
|
pro.SetExt( ProjectFileExtension );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
bool is_new = !wxFileName::IsFileReadable( fullFileName );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// If its a non-existent schematic and caller thinks it exists
|
|
|
|
if( is_new && !( aCtl & KICTL_CREATE ) )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// notify user that fullFileName does not exist, ask if user wants to create it.
|
2020-03-25 15:27:15 +00:00
|
|
|
msg.Printf( _( "Schematic \"%s\" does not exist. Do you wish to create it?" ),
|
|
|
|
fullFileName );
|
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
2010-05-17 20:35:46 +00:00
|
|
|
return false;
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:44:10 +00:00
|
|
|
// Loading a complex project and build data can be time
|
|
|
|
// consumming, so display a busy cursor
|
|
|
|
wxBusyCursor dummy;
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// unload current project file before loading new
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
2018-12-11 14:15:47 +00:00
|
|
|
SetScreen( nullptr );
|
2020-11-03 19:24:05 +00:00
|
|
|
m_toolManager->GetTool<EE_INSPECTION_TOOL>()->Reset( TOOL_BASE::MODEL_RELOAD );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
CreateScreens();
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2009-04-06 18:54:57 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
SetStatusText( wxEmptyString );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromSchPath( fullFileName );
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// PROJECT::SetProjectFullName() is an impactful function. It should only be
|
|
|
|
// called under carefully considered circumstances.
|
2008-02-12 21:12:46 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// The calling code should know not to ask me here to change projects unless
|
|
|
|
// it knows what consequences that will have on other KIFACEs running and using
|
|
|
|
// this same PROJECT. It can be very harmful if that calling code is stupid.
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2020-07-03 03:42:36 +00:00
|
|
|
// NOTE: The calling code should never call this in hosted (non-standalone) mode with a
|
|
|
|
// different project than what has been loaded by the manager frame. This will crash.
|
|
|
|
|
|
|
|
bool differentProject = pro.GetFullPath() != Prj().GetProjectFullName();
|
|
|
|
|
|
|
|
if( differentProject )
|
|
|
|
{
|
2020-08-25 02:17:21 +00:00
|
|
|
if( !Prj().IsNullProject() )
|
|
|
|
GetSettingsManager()->SaveProject();
|
|
|
|
|
2020-07-03 14:43:23 +00:00
|
|
|
Schematic().SetProject( nullptr );
|
2020-07-03 03:42:36 +00:00
|
|
|
GetSettingsManager()->UnloadProject( &Prj() );
|
2020-08-25 02:17:21 +00:00
|
|
|
|
2020-08-30 20:04:39 +00:00
|
|
|
GetSettingsManager()->LoadProject( pro.GetFullPath() );
|
|
|
|
|
|
|
|
// Do not allow saving a project if one doesn't exist. This normally happens if we are
|
2020-10-06 02:13:06 +00:00
|
|
|
// standalone and opening a schematic that has been moved from its project folder.
|
|
|
|
if( !pro.Exists() && !( aCtl & KICTL_CREATE ) )
|
2020-08-30 20:04:39 +00:00
|
|
|
Prj().SetReadOnly();
|
2020-08-25 02:17:21 +00:00
|
|
|
|
2020-07-03 14:43:23 +00:00
|
|
|
CreateScreens();
|
2020-07-03 03:42:36 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
if( schFileType == SCH_IO_MGR::SCH_LEGACY )
|
2017-02-18 00:31:47 +00:00
|
|
|
{
|
2020-04-16 16:43:50 +00:00
|
|
|
// Don't reload the symbol libraries if we are just launching Eeschema from KiCad again.
|
|
|
|
// They are already saved in the kiface project object.
|
2020-07-03 03:42:36 +00:00
|
|
|
if( differentProject || !Prj().GetElem( PROJECT::ELEM_SCH_PART_LIBS ) )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
|
|
|
// load the libraries here, not in SCH_SCREEN::Draw() which is a context
|
|
|
|
// that will not tolerate DisplayError() dialog since we're already in an
|
|
|
|
// event handler in there.
|
|
|
|
// And when a schematic file is loaded, we need these libs to initialize
|
|
|
|
// some parameters (links to PART LIB, dangling ends ...)
|
|
|
|
Prj().SetElem( PROJECT::ELEM_SCH_PART_LIBS, NULL );
|
|
|
|
Prj().SchLibs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No legacy symbol libraries including the cache are loaded with the new file format.
|
2017-02-18 00:31:47 +00:00
|
|
|
Prj().SetElem( PROJECT::ELEM_SCH_PART_LIBS, NULL );
|
|
|
|
}
|
2014-08-18 16:39:51 +00:00
|
|
|
|
2017-03-05 22:31:31 +00:00
|
|
|
// Load the symbol library table, this will be used forever more.
|
|
|
|
Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL );
|
|
|
|
Prj().SchSymbolLibTable();
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
// Load project settings after schematic has been set up with the project link, since this will
|
|
|
|
// update some of the needed schematic settings such as drawing defaults
|
|
|
|
LoadProjectSettings();
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2020-08-24 02:01:14 +00:00
|
|
|
wxFileName rfn( GetCurrentFileName() );
|
|
|
|
rfn.MakeRelativeTo( Prj().GetProjectPath() );
|
|
|
|
LoadWindowState( rfn.GetFullPath() );
|
|
|
|
|
2020-09-01 10:14:51 +00:00
|
|
|
KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Schematic file changes are unsaved" ) );
|
|
|
|
|
2020-07-21 00:33:35 +00:00
|
|
|
if( Kiface().IsSingle() )
|
|
|
|
{
|
|
|
|
KIPLATFORM::APP::RegisterApplicationRestart( fullFileName );
|
|
|
|
}
|
2019-12-19 14:11:11 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( is_new )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// mark new, unsaved file as modified.
|
|
|
|
GetScreen()->SetModify();
|
2020-10-06 02:13:06 +00:00
|
|
|
GetScreen()->SetFileName( fullFileName );
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
else
|
|
|
|
{
|
2020-09-01 20:52:05 +00:00
|
|
|
// This will rename the file if there is an autosave and the user want to recover.
|
|
|
|
CheckForAutoSaveFile( fullFileName );
|
|
|
|
|
2018-12-11 14:15:47 +00:00
|
|
|
SetScreen( nullptr );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-03-25 15:27:15 +00:00
|
|
|
SCH_PLUGIN* plugin = SCH_IO_MGR::FindPlugin( schFileType );
|
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( plugin );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-05-21 03:00:23 +00:00
|
|
|
Schematic().SetRoot( pi->Load( fullFileName, &Schematic() ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2017-12-07 00:10:45 +00:00
|
|
|
if( !pi->GetError().IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this,
|
2018-02-21 16:29:24 +00:00
|
|
|
_( "The entire schematic could not be loaded. Errors "
|
|
|
|
"occurred attempting to load \nhierarchical sheet "
|
2017-12-07 00:10:45 +00:00
|
|
|
"schematics." ),
|
|
|
|
pi->GetError() );
|
|
|
|
}
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2017-03-06 20:30:51 +00:00
|
|
|
// Do not leave g_RootSheet == NULL because it is expected to be
|
|
|
|
// a valid sheet. Therefore create a dummy empty root sheet and screen.
|
|
|
|
CreateScreens();
|
2019-06-04 12:46:02 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
|
2017-03-06 20:30:51 +00:00
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Error loading schematic file \"%s\".\n%s" ),
|
2020-04-16 16:43:50 +00:00
|
|
|
fullFileName, ioe.What() );
|
2016-07-06 09:22:56 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
msg.Printf( _( "Failed to load \"%s\"" ), fullFileName );
|
2020-12-08 05:27:34 +00:00
|
|
|
SetMsgPanel( wxEmptyString, msg );
|
2016-07-07 13:09:32 +00:00
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-04 14:57:26 +00:00
|
|
|
|
2017-03-30 19:44:47 +00:00
|
|
|
// It's possible the schematic parser fixed errors due to bugs so warn the user
|
|
|
|
// that the schematic has been fixed (modified).
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SHEET_LIST sheetList = Schematic().GetSheets();
|
2017-03-30 19:44:47 +00:00
|
|
|
|
|
|
|
if( sheetList.IsModified() )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( this,
|
|
|
|
_( "An error was found when loading the schematic that has "
|
|
|
|
"been automatically fixed. Please save the schematic to "
|
|
|
|
"repair the broken file or it may not be usable with other "
|
|
|
|
"versions of KiCad." ) );
|
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
if( sheetList.AllSheetPageNumbersEmpty() )
|
|
|
|
sheetList.SetInitialPageNumbers();
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
UpdateFileHistory( fullFileName );
|
2015-04-25 22:26:51 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREENS schematic( Schematic().Root() );
|
2017-03-05 18:18:26 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
// LIB_ID checks and symbol rescue only apply to the legacy file formats.
|
|
|
|
if( schFileType == SCH_IO_MGR::SCH_LEGACY )
|
2017-09-01 20:42:20 +00:00
|
|
|
{
|
2020-04-16 16:43:50 +00:00
|
|
|
// Convert old projects over to use symbol library table.
|
|
|
|
if( schematic.HasNoFullyDefinedLibIds() )
|
|
|
|
{
|
|
|
|
DIALOG_SYMBOL_REMAP dlgRemap( this );
|
2017-09-01 20:42:20 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
dlgRemap.ShowQuasiModal();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Double check to ensure no legacy library list entries have been
|
|
|
|
// added to the projec file symbol library list.
|
|
|
|
wxString paths;
|
|
|
|
wxArrayString libNames;
|
2019-08-01 17:26:21 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
PART_LIBS::LibNamesAndPaths( &Prj(), false, &paths, &libNames );
|
2019-08-01 17:26:21 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
if( !libNames.IsEmpty() )
|
2019-08-01 17:26:21 +00:00
|
|
|
{
|
2020-04-16 16:43:50 +00:00
|
|
|
if( eeconfig()->m_Appearance.show_illegal_symbol_lib_dialog )
|
|
|
|
{
|
|
|
|
wxRichMessageDialog invalidLibDlg(
|
|
|
|
this,
|
|
|
|
_( "Illegal entry found in project file symbol library list." ),
|
|
|
|
_( "Project Load Warning" ),
|
|
|
|
wxOK | wxCENTER | wxICON_EXCLAMATION );
|
|
|
|
invalidLibDlg.ShowDetailedText(
|
|
|
|
_( "Symbol libraries defined in the project file symbol library "
|
2020-09-29 07:31:13 +00:00
|
|
|
"list are no longer supported and will be removed.\n\nThis may "
|
2020-04-16 16:43:50 +00:00
|
|
|
"cause broken symbol library links under certain conditions." ) );
|
|
|
|
invalidLibDlg.ShowCheckBox( _( "Do not show this dialog again." ) );
|
|
|
|
invalidLibDlg.ShowModal();
|
|
|
|
eeconfig()->m_Appearance.show_illegal_symbol_lib_dialog =
|
|
|
|
!invalidLibDlg.IsCheckBoxChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
libNames.Clear();
|
|
|
|
paths.Clear();
|
|
|
|
PART_LIBS::LibNamesAndPaths( &Prj(), true, &paths, &libNames );
|
2019-08-01 17:26:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
if( !cfg || !cfg->m_RescueNeverShow )
|
2020-05-12 17:12:38 +00:00
|
|
|
{
|
|
|
|
SCH_EDITOR_CONTROL* editor = m_toolManager->GetTool<SCH_EDITOR_CONTROL>();
|
|
|
|
editor->RescueSymbolLibTableProject( false );
|
|
|
|
}
|
2019-08-01 17:26:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
// Update all symbol library links for all sheets.
|
|
|
|
schematic.UpdateSymbolLinks();
|
2017-10-22 00:48:25 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
if( !cfg || cfg->m_Appearance.show_sexpr_file_convert_warning )
|
|
|
|
{
|
|
|
|
wxRichMessageDialog newFileFormatDlg(
|
|
|
|
this,
|
|
|
|
_( "The schematic file will be converted to the new file format on save." ),
|
|
|
|
_( "Project Load Warning" ),
|
|
|
|
wxOK | wxCENTER | wxICON_EXCLAMATION );
|
|
|
|
newFileFormatDlg.ShowDetailedText(
|
|
|
|
_( "This schematic was saved in the legacy file format which is no "
|
2020-09-29 07:31:13 +00:00
|
|
|
"longer supported and will be saved using the new file format.\n\nThe "
|
2020-04-16 16:43:50 +00:00
|
|
|
"new file format cannot be opened with previous versions of KiCad." ) );
|
|
|
|
newFileFormatDlg.ShowCheckBox( _( "Do not show this dialog again." ) );
|
|
|
|
newFileFormatDlg.ShowModal();
|
2020-05-05 19:12:56 +00:00
|
|
|
|
|
|
|
if( cfg )
|
|
|
|
cfg->m_Appearance.show_sexpr_file_convert_warning =
|
|
|
|
!newFileFormatDlg.IsCheckBoxChecked();
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 15:01:00 +00:00
|
|
|
// Legacy schematic can have duplicate time stamps so fix that before converting
|
|
|
|
// to the s-expression format.
|
|
|
|
schematic.ReplaceDuplicateTimeStamps();
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
// Allow the schematic to be saved to new file format without making any edits.
|
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
else // S-expression schematic.
|
|
|
|
{
|
|
|
|
for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() )
|
|
|
|
screen->UpdateLocalLibSymbolLinks();
|
2020-04-26 20:53:29 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
// Restore all of the loaded symbol and sheet instances from the root sheet.
|
2020-09-06 10:28:58 +00:00
|
|
|
sheetList.UpdateSymbolInstances( Schematic().RootScreen()->GetSymbolInstances() );
|
2020-10-18 20:30:37 +00:00
|
|
|
sheetList.UpdateSheetInstances( Schematic().RootScreen()->GetSheetInstances() );
|
2017-10-22 00:48:25 +00:00
|
|
|
}
|
2017-09-01 20:42:20 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
Schematic().ConnectionGraph()->Reset();
|
2020-02-04 22:37:14 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SetScreen( GetCurrentSheet().LastScreen() );
|
2017-11-27 19:27:24 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
// Migrate conflicting bus definitions
|
|
|
|
// TODO(JE) This should only run once based on schematic file version
|
2020-05-13 02:00:37 +00:00
|
|
|
if( Schematic().ConnectionGraph()->GetBusesNeedingMigration().size() > 0 )
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
|
|
|
DIALOG_MIGRATE_BUSES dlg( this );
|
|
|
|
dlg.ShowQuasiModal();
|
2020-02-04 22:37:14 +00:00
|
|
|
RecalculateConnections( NO_CLEANUP );
|
2019-03-11 21:32:05 +00:00
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
RecalculateConnections( GLOBAL_CLEANUP );
|
2020-07-13 11:21:40 +00:00
|
|
|
ClearUndoRedoList();
|
2018-09-16 21:19:33 +00:00
|
|
|
GetScreen()->m_Initialized = true;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|
2011-04-17 17:11:53 +00:00
|
|
|
|
2020-11-19 18:22:26 +00:00
|
|
|
// Load any exclusions from the project file
|
|
|
|
ResolveERCExclusions();
|
|
|
|
|
2019-06-04 12:46:02 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
|
2008-04-30 17:04:22 +00:00
|
|
|
SetSheetNumberAndCount();
|
2019-06-23 15:12:25 +00:00
|
|
|
|
2020-11-29 16:31:43 +00:00
|
|
|
RecomputeIntersheetRefs();
|
2020-11-19 19:21:15 +00:00
|
|
|
|
2019-07-19 15:39:29 +00:00
|
|
|
// re-create junctions if needed. Eeschema optimizes wires by merging
|
2019-06-23 15:12:25 +00:00
|
|
|
// colinear segments. If a schematic is saved without a valid
|
|
|
|
// cache library or missing installed libraries, this can cause connectivity errors
|
|
|
|
// unless junctions are added.
|
|
|
|
FixupJunctions();
|
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
SyncView();
|
2017-12-19 00:05:18 +00:00
|
|
|
GetScreen()->ClearDrawingState();
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2019-03-15 12:09:04 +00:00
|
|
|
UpdateTitle();
|
|
|
|
|
2020-05-18 23:44:58 +00:00
|
|
|
wxFileName fn = Prj().AbsolutePath( GetScreen()->GetFileName() );
|
2020-05-20 01:31:47 +00:00
|
|
|
m_infoBar->Dismiss();
|
2020-05-18 23:44:58 +00:00
|
|
|
|
|
|
|
if( fn.FileExists() && !fn.IsFileWritable() )
|
|
|
|
{
|
|
|
|
m_infoBar->RemoveAllButtons();
|
|
|
|
m_infoBar->AddCloseButton();
|
2021-01-12 13:26:18 +00:00
|
|
|
m_infoBar->ShowMessage( _( "Schematic file is read only." ), wxICON_WARNING );
|
2020-05-18 23:44:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 21:57:16 +00:00
|
|
|
#ifdef PROFILE
|
|
|
|
openFiles.Show();
|
|
|
|
#endif
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-07-18 07:04:43 +00:00
|
|
|
|
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
bool SCH_EDIT_FRAME::AppendSchematic()
|
2013-01-24 17:46:37 +00:00
|
|
|
{
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
wxString fullFileName;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2013-01-24 17:46:37 +00:00
|
|
|
|
|
|
|
if( !screen )
|
|
|
|
{
|
2016-07-11 19:48:46 +00:00
|
|
|
wxLogError( wxT( "Document not ready, cannot import" ) );
|
2013-01-24 17:46:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// open file chooser dialog
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxString path = wxPathOnly( Prj().GetProjectFullName() );
|
|
|
|
|
2018-08-01 23:06:12 +00:00
|
|
|
wxFileDialog dlg( this, _( "Append Schematic" ), path, wxEmptyString,
|
2020-04-16 16:43:50 +00:00
|
|
|
KiCadSchematicFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
2013-01-24 17:46:37 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
fullFileName = dlg.GetPath();
|
2013-01-24 17:46:37 +00:00
|
|
|
|
2019-07-29 19:59:31 +00:00
|
|
|
if( !LoadSheetFromFile( GetCurrentSheet().Last(), &GetCurrentSheet(), fullFileName ) )
|
2017-11-17 17:00:04 +00:00
|
|
|
return false;
|
|
|
|
|
2019-06-04 12:46:02 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
|
2013-01-24 17:46:37 +00:00
|
|
|
SetSheetNumberAndCount();
|
2018-10-18 09:50:43 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
SyncView();
|
2018-10-18 09:50:43 +00:00
|
|
|
OnModify();
|
2020-12-06 21:23:16 +00:00
|
|
|
HardRedraw(); // Full reinit of the current screen and the display.
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
return true;
|
2013-01-24 17:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::OnAppendProject( wxCommandEvent& event )
|
|
|
|
{
|
2017-11-17 17:00:04 +00:00
|
|
|
if( GetScreen() && GetScreen()->IsModified() )
|
|
|
|
{
|
|
|
|
wxString msg = _( "This operation cannot be undone.\n\n"
|
|
|
|
"Do you want to save the current document before proceeding?" );
|
2013-01-24 17:46:37 +00:00
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
if( IsOK( this, msg ) )
|
2018-08-01 23:06:12 +00:00
|
|
|
SaveProject();
|
2017-11-17 17:00:04 +00:00
|
|
|
}
|
2013-01-24 17:46:37 +00:00
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
AppendSchematic();
|
2013-01-24 17:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-20 14:20:38 +00:00
|
|
|
void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( !AskToSaveChanges() )
|
|
|
|
return;
|
|
|
|
|
2017-12-12 14:28:21 +00:00
|
|
|
// Set the project location if none is set
|
|
|
|
bool setProject = Prj().GetProjectFullName().IsEmpty();
|
2017-09-20 14:20:38 +00:00
|
|
|
wxString path = wxPathOnly( Prj().GetProjectFullName() );
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
// clang-format off
|
|
|
|
std::list<std::pair<const wxString, const SCH_IO_MGR::SCH_FILE_T>> loaders;
|
|
|
|
|
|
|
|
if( ADVANCED_CFG::GetCfg().m_PluginAltiumSch )
|
|
|
|
loaders.emplace_back( AltiumSchematicFileWildcard(), SCH_IO_MGR::SCH_ALTIUM ); // Import Altium schematic files
|
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
loaders.emplace_back( CadstarSchematicArchiveFileWildcard(), SCH_IO_MGR::SCH_CADSTAR_ARCHIVE ); //Import CADSTAR Schematic Archive files
|
2020-08-23 19:01:08 +00:00
|
|
|
loaders.emplace_back( EagleSchematicFileWildcard(), SCH_IO_MGR::SCH_EAGLE ); // Import Eagle schematic files
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
wxString fileFilters;
|
2020-10-02 19:43:02 +00:00
|
|
|
wxString allWildcards;
|
2020-08-23 19:01:08 +00:00
|
|
|
|
|
|
|
for( auto& loader : loaders )
|
|
|
|
{
|
|
|
|
if( !fileFilters.IsEmpty() )
|
|
|
|
fileFilters += wxChar( '|' );
|
|
|
|
|
|
|
|
fileFilters += wxGetTranslation( loader.first );
|
2020-10-02 19:43:02 +00:00
|
|
|
|
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin( SCH_IO_MGR::FindPlugin( loader.second ) );
|
|
|
|
wxCHECK( plugin, /*void*/ );
|
|
|
|
allWildcards += "*." + formatWildcardExt( plugin->GetFileExtension() ) + ";";
|
2020-08-23 19:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 19:43:02 +00:00
|
|
|
fileFilters = _( "All supported formats|" ) + allWildcards + "|" + fileFilters;
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
wxFileDialog dlg( this, _( "Import Schematic" ), path, wxEmptyString, fileFilters,
|
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST ); // TODO
|
2017-09-20 14:20:38 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2017-12-12 14:28:21 +00:00
|
|
|
if( setProject )
|
|
|
|
{
|
2020-08-25 02:17:21 +00:00
|
|
|
if( !Prj().IsNullProject() )
|
|
|
|
GetSettingsManager()->SaveProject();
|
|
|
|
|
2020-07-08 00:48:21 +00:00
|
|
|
Schematic().SetProject( nullptr );
|
|
|
|
GetSettingsManager()->UnloadProject( &Prj() );
|
|
|
|
|
|
|
|
Schematic().Reset();
|
|
|
|
|
2017-12-12 14:28:21 +00:00
|
|
|
wxFileName projectFn( dlg.GetPath() );
|
2020-05-25 20:41:24 +00:00
|
|
|
projectFn.SetExt( ProjectFileExtension );
|
|
|
|
GetSettingsManager()->LoadProject( projectFn.GetFullPath() );
|
2020-07-08 00:48:21 +00:00
|
|
|
|
|
|
|
Schematic().SetProject( &Prj() );
|
2017-12-12 14:28:21 +00:00
|
|
|
}
|
|
|
|
|
2020-08-23 19:01:08 +00:00
|
|
|
wxFileName fn = dlg.GetPath();
|
|
|
|
|
|
|
|
SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN;
|
|
|
|
|
|
|
|
for( auto& loader : loaders )
|
|
|
|
{
|
|
|
|
if( fn.GetExt().CmpNoCase( SCH_IO_MGR::GetFileExtension( loader.second ) ) == 0 )
|
|
|
|
{
|
|
|
|
pluginType = loader.second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pluginType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format( "unexpected file extension: %s", fn.GetExt() ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
importFile( dlg.GetPath(), pluginType );
|
2017-09-20 14:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-01 23:06:12 +00:00
|
|
|
bool SCH_EDIT_FRAME::SaveProject()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-04-26 20:53:29 +00:00
|
|
|
wxString msg;
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREEN* screen;
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREENS screens( Schematic().Root() );
|
2018-08-01 23:06:12 +00:00
|
|
|
bool success = true;
|
2020-04-16 16:43:50 +00:00
|
|
|
bool updateFileType = false;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// I want to see it in the debugger, show me the string! Can't do that with wxFileName.
|
2020-05-13 02:00:37 +00:00
|
|
|
wxString fileName = Prj().AbsolutePath( Schematic().Root().GetFileName() );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxFileName fn = fileName;
|
2011-08-18 19:25:12 +00:00
|
|
|
|
2020-10-12 23:41:38 +00:00
|
|
|
if( fn.IsOk() && !fn.IsDirWritable() )
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
{
|
2020-04-26 20:53:29 +00:00
|
|
|
msg = wxString::Format( _( "Directory \"%s\" is not writable." ), fn.GetPath() );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
DisplayError( this, msg );
|
2018-08-01 23:06:12 +00:00
|
|
|
return false;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|
2011-08-18 19:25:12 +00:00
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
// Warn user on potential file overwrite. This can happen on shared sheets.
|
|
|
|
wxArrayString overwrittenFiles;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < screens.GetCount(); i++ )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2020-04-26 20:53:29 +00:00
|
|
|
screen = screens.GetScreen( i );
|
|
|
|
|
|
|
|
wxCHECK2( screen, continue );
|
|
|
|
|
|
|
|
// Convert legacy schematics file name extensions for the new format.
|
|
|
|
wxFileName tmpFn = screen->GetFileName();
|
|
|
|
|
2020-10-12 23:41:38 +00:00
|
|
|
if( !tmpFn.IsOk() )
|
|
|
|
continue;
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
if( tmpFn.GetExt() == KiCadSchematicFileExtension )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tmpFn.SetExt( KiCadSchematicFileExtension );
|
|
|
|
|
|
|
|
if( tmpFn.FileExists() )
|
|
|
|
overwrittenFiles.Add( tmpFn.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !overwrittenFiles.IsEmpty() )
|
|
|
|
{
|
|
|
|
for( auto overwrittenFile : overwrittenFiles )
|
|
|
|
{
|
|
|
|
if( msg.IsEmpty() )
|
|
|
|
msg = overwrittenFile;
|
|
|
|
else
|
|
|
|
msg += "\n" + overwrittenFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxRichMessageDialog dlg(
|
|
|
|
this,
|
|
|
|
_( "Saving the project to the new file format will overwrite existing files." ),
|
|
|
|
_( "Project Save Warning" ),
|
|
|
|
wxOK | wxCANCEL | wxCANCEL_DEFAULT | wxCENTER | wxICON_EXCLAMATION );
|
2020-05-10 14:55:15 +00:00
|
|
|
dlg.ShowDetailedText( wxString::Format(
|
|
|
|
_( "The following files will be overwritten:\n\n%s" ), msg ) );
|
2020-04-26 20:53:29 +00:00
|
|
|
dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel( _( "Overwrite Files" ) ),
|
|
|
|
wxMessageDialog::ButtonLabel( _( "Abort Project Save" ) ) );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-02 18:57:43 +00:00
|
|
|
screens.BuildClientSheetPathList();
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
for( size_t i = 0; i < screens.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
screen = screens.GetScreen( i );
|
|
|
|
|
|
|
|
wxCHECK2( screen, continue );
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
// Convert legacy schematics file name extensions for the new format.
|
|
|
|
wxFileName tmpFn = screen->GetFileName();
|
|
|
|
|
2020-10-12 23:41:38 +00:00
|
|
|
if( tmpFn.IsOk() && tmpFn.GetExt() != KiCadSchematicFileExtension )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
|
|
|
updateFileType = true;
|
|
|
|
tmpFn.SetExt( KiCadSchematicFileExtension );
|
|
|
|
|
|
|
|
for( auto item : screen->Items().OfType( SCH_SHEET_T ) )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
|
|
|
|
wxFileName sheetFileName = sheet->GetFileName();
|
|
|
|
|
2020-10-12 23:41:38 +00:00
|
|
|
if( !sheetFileName.IsOk() || sheetFileName.GetExt() == KiCadSchematicFileExtension )
|
2020-04-16 16:43:50 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
sheetFileName.SetExt( KiCadSchematicFileExtension );
|
|
|
|
sheet->SetFileName( sheetFileName.GetFullPath() );
|
2020-08-10 11:40:58 +00:00
|
|
|
UpdateItem( sheet );
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
screen->SetFileName( tmpFn.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
2020-07-31 21:03:25 +00:00
|
|
|
std::vector<SCH_SHEET_PATH>& sheets = screen->GetClientSheetPaths();
|
|
|
|
|
|
|
|
if( sheets.size() == 1 )
|
2020-10-18 20:30:37 +00:00
|
|
|
screen->SetVirtualPageNumber( 1 );
|
2020-07-31 21:03:25 +00:00
|
|
|
else
|
2020-10-18 20:30:37 +00:00
|
|
|
screen->SetVirtualPageNumber( 0 ); // multiple uses; no way to store the real sheet #
|
2020-07-31 21:03:25 +00:00
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
success &= SaveEEFile( screens.GetSheet( i ) );
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
if( updateFileType )
|
2020-05-13 02:00:37 +00:00
|
|
|
UpdateFileHistory( Schematic().RootScreen()->GetFileName() );
|
2013-02-01 07:58:49 +00:00
|
|
|
|
2020-02-20 22:52:01 +00:00
|
|
|
// Save the sheet name map to the project file
|
2020-05-26 02:27:27 +00:00
|
|
|
std::vector<FILE_INFO_PAIR>& sheets = Prj().GetProjectFile().GetSheets();
|
|
|
|
sheets.clear();
|
2020-02-20 19:43:39 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
for( SCH_SHEET_PATH& sheetPath : Schematic().GetSheets() )
|
2020-02-20 19:43:39 +00:00
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = sheetPath.Last();
|
2020-05-26 02:27:27 +00:00
|
|
|
sheets.emplace_back( std::make_pair( sheet->m_Uuid, sheet->GetName() ) );
|
2020-02-20 19:43:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 02:17:21 +00:00
|
|
|
if( !Prj().IsNullProject() )
|
|
|
|
Pgm().GetSettingsManager().SaveProject();
|
2020-02-20 19:43:39 +00:00
|
|
|
|
2020-07-12 15:42:05 +00:00
|
|
|
if( !Kiface().IsSingle() )
|
|
|
|
{
|
|
|
|
WX_STRING_REPORTER backupReporter( &msg );
|
2020-07-03 13:40:31 +00:00
|
|
|
|
2020-07-12 15:42:05 +00:00
|
|
|
if( !GetSettingsManager()->TriggerBackupIfNeeded( backupReporter ) )
|
|
|
|
SetStatusText( msg, 0 );
|
|
|
|
}
|
2020-07-03 13:40:31 +00:00
|
|
|
|
2013-02-01 07:58:49 +00:00
|
|
|
UpdateTitle();
|
2018-08-01 23:06:12 +00:00
|
|
|
|
|
|
|
return success;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2011-10-15 13:25:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::doAutoSave()
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
wxFileName tmpFileName = Schematic().Root().GetFileName();
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxFileName fn = tmpFileName;
|
2011-10-15 13:25:57 +00:00
|
|
|
wxFileName tmp;
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREENS screens( Schematic().Root() );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
bool autoSaveOk = true;
|
|
|
|
|
2020-12-17 02:17:48 +00:00
|
|
|
if( fn.GetPath().IsEmpty() )
|
|
|
|
tmp.AssignDir( Prj().GetProjectPath() );
|
|
|
|
else
|
|
|
|
tmp.AssignDir( fn.GetPath() );
|
2011-10-15 13:25:57 +00:00
|
|
|
|
2015-06-18 18:43:26 +00:00
|
|
|
if( !tmp.IsOk() )
|
|
|
|
return false;
|
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
if( !IsWritable( tmp ) )
|
|
|
|
return false;
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
for( size_t i = 0; i < screens.GetCount(); i++ )
|
2011-10-15 13:25:57 +00:00
|
|
|
{
|
|
|
|
// Only create auto save files for the schematics that have been modified.
|
2020-04-26 20:53:29 +00:00
|
|
|
if( !screens.GetScreen( i )->IsSave() )
|
2011-10-15 13:25:57 +00:00
|
|
|
continue;
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
tmpFileName = fn = screens.GetScreen( i )->GetFileName();
|
2011-10-15 13:25:57 +00:00
|
|
|
|
2019-03-18 12:22:33 +00:00
|
|
|
// Auto save file name is the normal file name prefixed with GetAutoSavePrefix().
|
|
|
|
fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() );
|
2011-10-15 13:25:57 +00:00
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
screens.GetScreen( i )->SetFileName( fn.GetFullPath() );
|
2011-10-15 13:25:57 +00:00
|
|
|
|
2020-06-20 01:06:52 +00:00
|
|
|
if( SaveEEFile( screens.GetSheet( i ), false ) )
|
2020-04-26 20:53:29 +00:00
|
|
|
screens.GetScreen( i )->SetModify();
|
2011-10-15 13:25:57 +00:00
|
|
|
else
|
|
|
|
autoSaveOk = false;
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
screens.GetScreen( i )->SetFileName( tmpFileName.GetFullPath() );
|
2011-10-15 13:25:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( autoSaveOk )
|
2020-07-03 13:40:31 +00:00
|
|
|
{
|
2011-10-15 13:25:57 +00:00
|
|
|
m_autoSaveState = false;
|
|
|
|
|
2020-07-12 15:42:05 +00:00
|
|
|
if( !Kiface().IsSingle() &&
|
|
|
|
GetSettingsManager()->GetCommonSettings()->m_Backup.backup_on_autosave )
|
|
|
|
{
|
2020-07-03 13:40:31 +00:00
|
|
|
GetSettingsManager()->TriggerBackupIfNeeded( NULL_REPORTER::GetInstance() );
|
2020-07-12 15:42:05 +00:00
|
|
|
}
|
2020-07-03 13:40:31 +00:00
|
|
|
}
|
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
return autoSaveOk;
|
|
|
|
}
|
2017-08-24 15:56:15 +00:00
|
|
|
|
|
|
|
|
2018-02-26 10:34:36 +00:00
|
|
|
bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType )
|
2017-10-03 10:23:52 +00:00
|
|
|
{
|
|
|
|
wxFileName newfilename;
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SHEET_LIST sheetList = Schematic().GetSheets();
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2017-10-03 10:30:23 +00:00
|
|
|
switch( (SCH_IO_MGR::SCH_FILE_T) aFileType )
|
2017-10-03 10:23:52 +00:00
|
|
|
{
|
2020-08-23 19:01:08 +00:00
|
|
|
case SCH_IO_MGR::SCH_ALTIUM:
|
2020-09-19 22:05:02 +00:00
|
|
|
case SCH_IO_MGR::SCH_CADSTAR_ARCHIVE:
|
2018-10-24 19:37:32 +00:00
|
|
|
case SCH_IO_MGR::SCH_EAGLE:
|
|
|
|
// We insist on caller sending us an absolute path, if it does not, we say it's a bug.
|
|
|
|
wxASSERT_MSG( wxFileName( aFileName ).IsAbsolute(),
|
|
|
|
wxT( "Import eagle schematic caller didn't send full filename" ) );
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2018-10-24 19:37:32 +00:00
|
|
|
if( !LockFile( aFileName ) )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _( "Schematic file \"%s\" is already open." ),
|
|
|
|
aFileName );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2018-10-24 19:37:32 +00:00
|
|
|
try
|
|
|
|
{
|
2020-08-23 19:01:08 +00:00
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi(
|
|
|
|
SCH_IO_MGR::FindPlugin( (SCH_IO_MGR::SCH_FILE_T) aFileType ) );
|
2020-05-21 03:00:23 +00:00
|
|
|
Schematic().SetRoot( pi->Load( aFileName, &Schematic() ) );
|
2017-09-20 14:28:49 +00:00
|
|
|
|
2018-10-24 19:37:32 +00:00
|
|
|
// Eagle sheets do not use a worksheet frame by default, so set it to an empty one
|
2019-05-25 11:05:39 +00:00
|
|
|
WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance();
|
2018-10-24 19:37:32 +00:00
|
|
|
pglayout.SetEmptyLayout();
|
2018-02-28 15:43:33 +00:00
|
|
|
|
2018-10-24 19:37:32 +00:00
|
|
|
BASE_SCREEN::m_PageLayoutDescrFileName = "empty.kicad_wks";
|
2020-04-05 21:10:42 +00:00
|
|
|
wxFileName layoutfn( Prj().GetProjectPath(), BASE_SCREEN::m_PageLayoutDescrFileName );
|
2020-12-12 18:11:51 +00:00
|
|
|
wxFFile layoutfile;
|
2018-02-28 15:43:33 +00:00
|
|
|
|
2020-12-12 18:11:51 +00:00
|
|
|
if( layoutfile.Open( layoutfn.GetFullPath(), "wb" ) )
|
2018-10-24 19:37:32 +00:00
|
|
|
{
|
2019-05-25 11:05:39 +00:00
|
|
|
layoutfile.Write( WS_DATA_MODEL::EmptyLayout() );
|
2018-10-24 19:37:32 +00:00
|
|
|
layoutfile.Close();
|
|
|
|
}
|
2018-02-28 15:43:33 +00:00
|
|
|
|
2020-05-14 23:26:54 +00:00
|
|
|
newfilename.SetPath( Prj().GetProjectPath() );
|
|
|
|
newfilename.SetName( Prj().GetProjectName() );
|
2020-03-16 13:04:50 +00:00
|
|
|
newfilename.SetExt( LegacySchematicFileExtension );
|
2018-02-28 15:43:33 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SetScreen( GetCurrentSheet().LastScreen() );
|
2017-09-20 14:28:49 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
Schematic().Root().SetFileName( newfilename.GetFullPath() );
|
2018-10-24 19:37:32 +00:00
|
|
|
GetScreen()->SetFileName( newfilename.GetFullPath() );
|
|
|
|
GetScreen()->SetModify();
|
2020-07-08 00:48:21 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
SaveProjectSettings();
|
2017-09-20 14:28:49 +00:00
|
|
|
|
2018-10-24 19:37:32 +00:00
|
|
|
UpdateFileHistory( aFileName );
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREENS schematic( Schematic().Root() );
|
2018-10-24 19:37:32 +00:00
|
|
|
schematic.UpdateSymbolLinks(); // Update all symbol library links for all sheets.
|
2017-09-20 14:28:49 +00:00
|
|
|
|
2018-10-24 19:37:32 +00:00
|
|
|
GetScreen()->m_Initialized = true;
|
2018-02-28 10:31:02 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() )
|
2018-10-24 19:37:32 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : screen->Items().OfType( SCH_COMPONENT_T ) )
|
2018-02-27 16:05:46 +00:00
|
|
|
{
|
2018-10-24 19:37:32 +00:00
|
|
|
std::vector<wxPoint> pts;
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_COMPONENT* cmp = static_cast<SCH_COMPONENT*>( item );
|
2018-10-24 19:37:32 +00:00
|
|
|
|
|
|
|
// Update footprint LIB_ID to point to the imported Eagle library
|
2020-11-12 21:31:41 +00:00
|
|
|
SCH_FIELD* fpField = cmp->GetField( FOOTPRINT_FIELD );
|
2018-02-27 16:05:46 +00:00
|
|
|
|
2018-10-24 19:37:32 +00:00
|
|
|
if( !fpField->GetText().IsEmpty() )
|
2018-02-27 16:05:46 +00:00
|
|
|
{
|
2018-10-24 19:37:32 +00:00
|
|
|
LIB_ID fpId;
|
2020-12-17 23:32:23 +00:00
|
|
|
fpId.Parse( fpField->GetText(), true );
|
2018-10-24 19:37:32 +00:00
|
|
|
fpId.SetLibNickname( newfilename.GetName() );
|
|
|
|
fpField->SetText( fpId.Format() );
|
2018-02-27 16:05:46 +00:00
|
|
|
}
|
2018-10-24 19:37:32 +00:00
|
|
|
}
|
2017-09-20 14:28:49 +00:00
|
|
|
}
|
2020-07-13 11:21:40 +00:00
|
|
|
|
2018-10-24 19:37:32 +00:00
|
|
|
// Only perform the dangling end test on root sheet.
|
|
|
|
GetScreen()->TestDanglingEnds();
|
2019-11-10 23:24:27 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
ClearUndoRedoList();
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2019-06-04 12:46:02 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
|
2018-10-24 19:37:32 +00:00
|
|
|
SetSheetNumberAndCount();
|
|
|
|
SyncView();
|
|
|
|
UpdateTitle();
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
// Do not leave g_RootSheet == NULL because it is expected to be
|
|
|
|
// a valid sheet. Therefore create a dummy empty root sheet and screen.
|
|
|
|
CreateScreens();
|
2019-06-04 12:46:02 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2018-10-24 19:37:32 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Error loading schematic \"%s\".\n%s" ), aFileName, ioe.What() );
|
|
|
|
DisplayError( this, msg );
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2018-10-24 19:37:32 +00:00
|
|
|
msg.Printf( _( "Failed to load \"%s\"" ), aFileName );
|
2020-12-08 05:27:34 +00:00
|
|
|
SetMsgPanel( wxEmptyString, msg );
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
return false;
|
2018-10-24 19:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
2017-10-03 10:23:52 +00:00
|
|
|
}
|
2017-08-24 15:56:15 +00:00
|
|
|
}
|
2017-09-20 14:20:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::AskToSaveChanges()
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREENS screenList( Schematic().Root() );
|
2017-09-20 14:20:38 +00:00
|
|
|
|
|
|
|
// Save any currently open and modified project files.
|
|
|
|
for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
|
|
|
|
{
|
|
|
|
if( screen->IsModify() )
|
|
|
|
{
|
2019-06-17 15:59:39 +00:00
|
|
|
if( !HandleUnsavedChanges( this, _( "The current schematic has been modified. "
|
|
|
|
"Save changes?" ),
|
2018-08-11 20:46:03 +00:00
|
|
|
[&]()->bool { return SaveProject(); } ) )
|
2017-09-20 14:20:38 +00:00
|
|
|
{
|
2018-08-11 20:46:03 +00:00
|
|
|
return false;
|
2017-09-20 14:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|