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)
|
2018-03-03 13:34:46 +00:00
|
|
|
* Copyright (C) 1992-2018 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2011-10-17 20:01:27 +00:00
|
|
|
* @file eeschema/files-io.cpp
|
2011-10-15 13:25:57 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gestfich.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
* 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
|
|
|
#include <pgm_base.h>
|
2015-04-25 22:26:51 +00:00
|
|
|
#include <kiface_i.h>
|
2017-03-05 22:31:31 +00:00
|
|
|
#include <richio.h>
|
2018-04-13 13:58:25 +00:00
|
|
|
#include <trace_helpers.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <class_library.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <lib_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_sheet.h>
|
2013-09-25 19:09:57 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2013-01-24 17:46:37 +00:00
|
|
|
#include <sch_component.h>
|
2012-02-16 20:03:33 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2015-06-22 15:38:54 +00:00
|
|
|
#include <project_rescue.h>
|
2015-04-27 08:44:17 +00:00
|
|
|
#include <eeschema_config.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
#include <sch_legacy_plugin.h>
|
2017-06-21 12:41:00 +00:00
|
|
|
#include <sch_eagle_plugin.h>
|
2017-09-01 20:42:20 +00:00
|
|
|
#include <symbol_lib_table.h>
|
|
|
|
#include <dialog_symbol_remap.h>
|
2018-02-28 15:43:33 +00:00
|
|
|
#include <worksheet_shape_builder.h>
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, bool aSaveUnderNewName,
|
|
|
|
bool aCreateBackupFile )
|
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
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
if( aScreen == NULL )
|
|
|
|
aScreen = GetScreen();
|
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.
|
2011-08-18 19:25:12 +00:00
|
|
|
if( aScreen->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
|
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
|
|
|
schematicFileName = Prj().AbsolutePath( aScreen->GetFileName() );
|
2013-02-13 17:18:23 +00:00
|
|
|
|
|
|
|
if( aSaveUnderNewName )
|
2010-10-26 20:25:48 +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
|
|
|
wxFileDialog dlg( this, _( "Schematic Files" ),
|
2016-07-11 19:48:46 +00:00
|
|
|
wxPathOnly( Prj().GetProjectFullName() ),
|
2017-11-12 00:31:38 +00:00
|
|
|
schematicFileName.GetFullName(), SchematicFileWildcard(),
|
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
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
if( schematicFileName.GetExt() != SchematicFileExtension )
|
|
|
|
schematicFileName.SetExt( SchematicFileExtension );
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
// Create backup if requested
|
2013-02-13 17:18:23 +00:00
|
|
|
if( aCreateBackupFile && schematicFileName.FileExists() )
|
|
|
|
{
|
|
|
|
wxFileName backupFileName = schematicFileName;
|
2010-10-26 20:25:48 +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
|
|
|
// Rename the old file to a '.bak' one:
|
2013-02-13 17:18:23 +00:00
|
|
|
backupFileName.SetExt( SchematicBackupFileExtension );
|
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
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
if( backupFileName.FileExists() )
|
|
|
|
wxRemoveFile( backupFileName.GetFullPath() );
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
if( !wxRenameFile( schematicFileName.GetFullPath(), backupFileName.GetFullPath() ) )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Could not save backup of file \"%s\"" ),
|
2016-07-11 19:48:46 +00:00
|
|
|
GetChars( schematicFileName.GetFullPath() ) );
|
2013-02-13 17:18:23 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
2010-10-26 20:25:48 +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
|
|
|
// Save
|
2011-10-15 13:25:57 +00:00
|
|
|
wxLogTrace( traceAutoSave,
|
|
|
|
wxT( "Saving file <" ) + schematicFileName.GetFullPath() + wxT( ">" ) );
|
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
|
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
|
|
|
{
|
2017-01-27 15:56:36 +00:00
|
|
|
pi->Save( schematicFileName.GetFullPath(), aScreen, &Kiway() );
|
|
|
|
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" ),
|
2017-01-27 15:56:36 +00:00
|
|
|
GetChars( schematicFileName.GetFullPath() ), GetChars( ioe.What() ) );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Failed to save \"%s\"" ), GetChars( schematicFileName.GetFullPath() ) );
|
2017-01-27 15:56:36 +00:00
|
|
|
AppendMsgPanel( wxEmptyString, msg, CYAN );
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
success = false;
|
|
|
|
}
|
2010-10-26 20:25:48 +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;
|
2015-05-03 13:48:05 +00:00
|
|
|
autoSaveFileName.SetName( AUTOSAVE_PREFIX_FILENAME + 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() );
|
|
|
|
}
|
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
// Update the screen and frame info.
|
|
|
|
if( aSaveUnderNewName )
|
|
|
|
aScreen->SetFileName( schematicFileName.GetFullPath() );
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
aScreen->ClrSave();
|
2011-08-18 19:25:12 +00:00
|
|
|
aScreen->ClrModify();
|
2013-02-13 17:18:23 +00:00
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
msg.Printf( _( "File %s saved" ), GetChars( aScreen->GetFileName() ) );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::Save_File( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-30 02:37:06 +00:00
|
|
|
int id = event.GetId();
|
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
2012-09-28 17:47:41 +00:00
|
|
|
case ID_UPDATE_ONE_SHEET:
|
|
|
|
SaveEEFile( NULL );
|
2007-09-30 02:37:06 +00:00
|
|
|
break;
|
|
|
|
|
2012-09-28 17:47:41 +00:00
|
|
|
case ID_SAVE_ONE_SHEET_UNDER_NEW_NAME:
|
2013-01-21 19:58:02 +00:00
|
|
|
if( SaveEEFile( NULL, true ) )
|
|
|
|
{
|
2013-05-07 18:32:06 +00:00
|
|
|
CreateArchiveLibraryCacheFile( true );
|
2013-01-21 19:58:02 +00:00
|
|
|
}
|
2007-09-30 02:37:06 +00:00
|
|
|
break;
|
|
|
|
}
|
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:
|
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
|
|
|
// This is for python:
|
|
|
|
if( aFileSet.size() != 1 )
|
2013-01-24 17:46:37 +00:00
|
|
|
{
|
2017-11-17 17:00:04 +00:00
|
|
|
UTF8 msg = StrPrintf( "Eeschema:%s() takes only a single filename.", __func__ );
|
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
|
|
|
}
|
|
|
|
|
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 fullFileName( aFileSet[0] );
|
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
|
|
|
// 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( "bug in single_top.cpp or project manager." ) );
|
2013-01-24 17:46:37 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _(
|
2017-12-15 11:37:46 +00:00
|
|
|
"Schematic file \"%s\" is already open." ),
|
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
|
|
|
GetChars( fullFileName )
|
|
|
|
);
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
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.
|
|
|
|
wxString ask = wxString::Format( _(
|
2017-12-15 11:37:46 +00:00
|
|
|
"Schematic \"%s\" does not exist. Do you wish to create it?" ),
|
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
|
|
|
GetChars( fullFileName )
|
|
|
|
);
|
|
|
|
if( !IsOK( this, ask ) )
|
2010-05-17 20:35:46 +00:00
|
|
|
return false;
|
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
|
|
|
// unload current project file before loading 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
|
|
|
delete g_RootSheet;
|
|
|
|
g_RootSheet = NULL;
|
2009-04-06 18:54:57 +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
|
|
|
CreateScreens();
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2009-04-06 18:54:57 +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
|
|
|
GetScreen()->SetFileName( fullFileName );
|
* 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
|
|
|
g_RootSheet->SetFileName( fullFileName );
|
2016-02-15 20:24:59 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
SetStatusText( wxEmptyString );
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
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
|
|
|
// 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
|
|
|
|
2017-02-18 00:31:47 +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.
|
|
|
|
if( pro.GetFullPath() != Prj().GetProjectFullName()
|
|
|
|
|| !Prj().GetElem( PROJECT::ELEM_SCH_PART_LIBS ) )
|
|
|
|
{
|
|
|
|
Prj().SetProjectFullName( pro.GetFullPath() );
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
2014-08-18 16:39:51 +00:00
|
|
|
|
2018-04-04 14:18:12 +00:00
|
|
|
LoadProjectFile();
|
|
|
|
|
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();
|
|
|
|
|
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();
|
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
|
|
|
|
{
|
2016-07-06 09:22:56 +00:00
|
|
|
delete g_RootSheet; // Delete the current project.
|
|
|
|
g_RootSheet = NULL; // Force CreateScreens() to build new empty project on load failure.
|
2017-09-12 18:59:28 +00:00
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
g_RootSheet = pi->Load( fullFileName, &Kiway() );
|
|
|
|
m_CurrentSheet->clear();
|
|
|
|
m_CurrentSheet->push_back( g_RootSheet );
|
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();
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
|
2016-08-20 15:25:51 +00:00
|
|
|
wxString msg;
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Error loading schematic file \"%s\".\n%s" ),
|
2016-09-14 22:36:45 +00:00
|
|
|
GetChars( fullFileName ), GetChars( ioe.What() ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Failed to load \"%s\"" ), GetChars( fullFileName ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
AppendMsgPanel( wxEmptyString, msg, CYAN );
|
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
|
|
|
|
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
|
|
|
SetScreen( m_CurrentSheet->LastScreen() );
|
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).
|
|
|
|
SCH_SHEET_LIST sheetList( g_RootSheet );
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-03-05 18:18:26 +00:00
|
|
|
SCH_SCREENS schematic;
|
|
|
|
|
2017-09-01 20:42:20 +00:00
|
|
|
// Convert old projects over to use symbol library table.
|
|
|
|
if( schematic.HasNoFullyDefinedLibIds() )
|
|
|
|
{
|
|
|
|
DIALOG_SYMBOL_REMAP dlgRemap( this );
|
|
|
|
|
|
|
|
dlgRemap.ShowQuasiModal();
|
|
|
|
}
|
2017-10-22 00:48:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Check to see whether some old library parts need to be rescued
|
|
|
|
// Only do this if RescueNeverShow was not set.
|
|
|
|
wxConfigBase *config = Kiface().KifaceSettings();
|
|
|
|
bool rescueNeverShow = false;
|
|
|
|
config->Read( RescueNeverShowEntry, &rescueNeverShow, false );
|
|
|
|
|
|
|
|
if( !rescueNeverShow )
|
|
|
|
RescueSymbolLibTableProject( false );
|
|
|
|
}
|
2017-09-01 20:42:20 +00:00
|
|
|
|
2017-03-05 18:18:26 +00:00
|
|
|
schematic.UpdateSymbolLinks(); // Update all symbol library links for all sheets.
|
2017-11-27 19:27:24 +00:00
|
|
|
|
|
|
|
// Ensure the schematic is fully segmented on first display
|
|
|
|
BreakSegmentsOnJunctions();
|
|
|
|
SchematicCleanUp( true );
|
|
|
|
GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 );
|
2017-03-05 18:18:26 +00:00
|
|
|
GetScreen()->TestDanglingEnds(); // Only perform the dangling end test on root sheet.
|
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
|
|
|
|
2010-05-17 20:35:46 +00:00
|
|
|
GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
|
2011-03-01 18:45:21 +00:00
|
|
|
Zoom_Automatique( false );
|
2008-04-30 17:04:22 +00:00
|
|
|
SetSheetNumberAndCount();
|
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
|
|
|
m_canvas->Refresh( true );
|
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
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-11-17 17:00:04 +00:00
|
|
|
wxString msg;
|
* 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;
|
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
|
|
|
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() );
|
|
|
|
|
2017-09-20 14:20:38 +00:00
|
|
|
wxFileDialog dlg( this, _( "Append Schematic" ), path,
|
2017-11-12 00:31:38 +00:00
|
|
|
wxEmptyString, SchematicFileWildcard(),
|
2013-01-24 17:46:37 +00:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
|
|
|
|
|
|
|
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
|
|
|
|
* 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
|
|
|
wxFileName fn = fullFileName;
|
2013-01-24 17:46:37 +00:00
|
|
|
|
|
|
|
if( fn.IsRelative() )
|
|
|
|
{
|
|
|
|
fn.MakeAbsolute();
|
* 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 = fn.GetFullPath();
|
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
|
|
|
wxString cache_name = PART_LIBS::CacheName( fullFileName );
|
2016-07-11 19:48: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
|
|
|
if( !!cache_name )
|
|
|
|
{
|
|
|
|
PART_LIBS* libs = Prj().SchLibs();
|
|
|
|
|
2017-02-12 01:14:45 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if( PART_LIB* lib = libs->AddLibrary( cache_name ) )
|
|
|
|
lib->SetCache();
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.What() );
|
|
|
|
}
|
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
|
|
|
}
|
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
|
|
|
wxLogDebug( wxT( "Importing schematic " ) + fullFileName );
|
2013-01-24 17:46:37 +00:00
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
// Load the schematic into a temporary sheet.
|
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
|
|
|
|
std::unique_ptr< SCH_SHEET> newSheet( new SCH_SHEET );
|
|
|
|
|
|
|
|
newSheet->SetFileName( fullFileName );
|
2015-03-10 18:31:21 +00:00
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
try
|
2016-07-11 19:48:46 +00:00
|
|
|
{
|
2017-11-17 17:00:04 +00:00
|
|
|
pi->Load( fullFileName, &Kiway(), newSheet.get() );
|
2017-12-07 00:10:45 +00:00
|
|
|
|
|
|
|
if( !pi->GetError().IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this,
|
|
|
|
_( "The entire schematic could not be load. Errors "
|
|
|
|
"occurred attempting to load hierarchical sheet "
|
|
|
|
"schematics." ),
|
|
|
|
pi->GetError() );
|
|
|
|
}
|
2016-07-11 19:48:46 +00:00
|
|
|
}
|
2017-11-17 17:00:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Error occurred loading schematic file \"%s\"." ), fullFileName );
|
2017-11-17 17:00:04 +00:00
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
2015-03-10 18:31:21 +00:00
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Failed to load schematic \"%s\"" ), fullFileName );
|
2017-11-17 17:00:04 +00:00
|
|
|
AppendMsgPanel( wxEmptyString, msg, CYAN );
|
2014-08-18 16:39:51 +00:00
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure any new sheet changes do not cause any recursion issues.
|
|
|
|
SCH_SHEET_LIST hierarchy( g_RootSheet ); // This is the schematic sheet hierarchy.
|
|
|
|
SCH_SHEET_LIST sheetHierarchy( newSheet.get() ); // This is the hierarchy of the import.
|
|
|
|
|
|
|
|
wxFileName destFile = screen->GetFileName();
|
|
|
|
|
|
|
|
if( destFile.IsRelative() )
|
|
|
|
destFile.MakeAbsolute( Prj().GetProjectPath() );
|
|
|
|
|
|
|
|
if( hierarchy.TestForRecursion( sheetHierarchy, destFile.GetFullPath( wxPATH_UNIX ) ) )
|
2013-01-24 17:46:37 +00:00
|
|
|
{
|
2017-11-17 17:00:04 +00:00
|
|
|
msg.Printf( _( "The sheet changes cannot be made because the destination sheet already "
|
2017-12-15 11:37:46 +00:00
|
|
|
"has the sheet \"%s\" or one of it's subsheets as a parent somewhere in "
|
2017-11-17 17:00:04 +00:00
|
|
|
"the schematic hierarchy." ),
|
|
|
|
destFile.GetFullPath() );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxArrayString names;
|
|
|
|
|
|
|
|
// Make sure the imported schematic has been remapped to the symbol library table.
|
|
|
|
SCH_SCREENS newScreens( newSheet.get() ); // All screens associated with the import.
|
2015-03-10 18:31:21 +00:00
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
if( newScreens.HasNoFullyDefinedLibIds() )
|
|
|
|
{
|
|
|
|
if( !IsOK( this,
|
|
|
|
"This schematic has not been remapped to the symbol library table. "
|
|
|
|
"Therefore, all of the library symbol links will be broken. Do you "
|
|
|
|
"want to continue?" ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If there are symbol libraries in the imported schematic that are not in the
|
|
|
|
// symbol library table of this project, there could be a lot of broken symbol
|
|
|
|
// library links. Attempt to add the missing libraries to the project symbol
|
|
|
|
// library table.
|
|
|
|
newScreens.GetLibNicknames( names );
|
|
|
|
wxArrayString newLibNames;
|
|
|
|
|
2017-09-24 18:11:58 +00:00
|
|
|
for( const auto& name : names )
|
2013-01-24 17:46:37 +00:00
|
|
|
{
|
2017-11-17 17:00:04 +00:00
|
|
|
if( !Prj().SchSymbolLibTable()->HasLibrary( name ) )
|
|
|
|
newLibNames.Add( name );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFileName symLibTableFn( fn.GetPath(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
|
|
|
|
|
|
|
|
if( !newLibNames.IsEmpty() && symLibTableFn.Exists() && symLibTableFn.IsFileReadable() )
|
|
|
|
{
|
|
|
|
SYMBOL_LIB_TABLE table;
|
|
|
|
|
|
|
|
try
|
2013-01-24 17:46:37 +00:00
|
|
|
{
|
2017-11-17 17:00:04 +00:00
|
|
|
table.Load( symLibTableFn.GetFullPath() );
|
2013-01-24 17:46:37 +00:00
|
|
|
}
|
2017-11-17 17:00:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2013-01-24 17:46:37 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "An error occurred loading the symbol library table \"%s\"." ),
|
2017-11-17 17:00:04 +00:00
|
|
|
symLibTableFn.GetFullPath() );
|
|
|
|
DisplayErrorMessage( NULL, msg, ioe.What() );
|
2013-01-24 17:46:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
if( !table.IsEmpty() )
|
|
|
|
{
|
2017-09-24 18:11:58 +00:00
|
|
|
for( const auto& libName : newLibNames )
|
2017-11-17 17:00:04 +00:00
|
|
|
{
|
|
|
|
if( !table.HasLibrary( libName ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Don't expand environment variable because KIPRJMOD will not be correct
|
|
|
|
// for a different project.
|
|
|
|
wxString uri = table.GetFullURI( libName, false );
|
|
|
|
|
|
|
|
wxFileName newLib;
|
|
|
|
|
|
|
|
if( uri.Contains( "${KIPRJMOD}" ) )
|
|
|
|
{
|
|
|
|
newLib.SetPath( fn.GetPath() );
|
|
|
|
newLib.SetFullName( uri.AfterLast( '}' ) );
|
|
|
|
uri = newLib.GetFullPath();
|
|
|
|
}
|
2018-05-05 22:39:43 +00:00
|
|
|
else if( uri.Contains( "$(KIPRJMOD)" ) )
|
|
|
|
{
|
|
|
|
newLib.SetPath( fn.GetPath() );
|
|
|
|
newLib.SetFullName( uri.AfterLast( ')' ) );
|
|
|
|
uri = newLib.GetFullPath();
|
|
|
|
}
|
2017-11-17 17:00:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
uri = table.GetFullURI( libName );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the library from the imported project to the current project
|
|
|
|
// symbol library table.
|
|
|
|
const SYMBOL_LIB_TABLE_ROW* row = table.FindRow( libName );
|
|
|
|
|
|
|
|
wxCHECK2_MSG( row, continue, "Library '" + libName +
|
|
|
|
"' missing from symbol library table '" +
|
|
|
|
symLibTableFn.GetFullPath() + "'." );
|
|
|
|
|
|
|
|
wxString newLibName = libName;
|
|
|
|
int libNameCnt = 1;
|
|
|
|
|
|
|
|
// Rename the imported symbol library if it already exists.
|
|
|
|
while( Prj().SchSymbolLibTable()->HasLibrary( newLibName ) )
|
|
|
|
{
|
|
|
|
newLibName = wxString::Format( "%s%d", libName, libNameCnt );
|
|
|
|
}
|
|
|
|
|
|
|
|
SYMBOL_LIB_TABLE_ROW* newRow = new SYMBOL_LIB_TABLE_ROW( newLibName,
|
|
|
|
uri,
|
|
|
|
row->GetType(),
|
|
|
|
row->GetOptions(),
|
|
|
|
row->GetDescr() );
|
|
|
|
Prj().SchSymbolLibTable()->InsertRow( newRow );
|
|
|
|
|
|
|
|
if( libName != newLibName )
|
|
|
|
newScreens.ChangeSymbolLibNickname( libName, newLibName );
|
|
|
|
}
|
|
|
|
}
|
2013-01-24 17:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-23 15:44:17 +00:00
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
// Check for duplicate sheet names in the current page.
|
|
|
|
wxArrayString duplicateSheetNames;
|
|
|
|
SCH_TYPE_COLLECTOR sheets;
|
|
|
|
|
|
|
|
sheets.Collect( screen->GetDrawItems(), SCH_COLLECTOR::SheetsOnly );
|
|
|
|
|
|
|
|
for( int i = 0; i < sheets.GetCount(); ++i )
|
|
|
|
{
|
|
|
|
if( newSheet->GetScreen()->GetSheet( ( ( SCH_SHEET* ) sheets[i] )->GetName() ) )
|
|
|
|
duplicateSheetNames.Add( ( ( SCH_SHEET* ) sheets[i] )->GetName() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !duplicateSheetNames.IsEmpty() )
|
|
|
|
{
|
|
|
|
msg.Printf( "Duplicate sheet names exist on the current page. Do you want to "
|
|
|
|
"automatically rename the duplicate sheet names?" );
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_SCREEN* newScreen = newSheet->GetScreen();
|
|
|
|
wxCHECK_MSG( newScreen, false, "No screen defined for imported sheet." );
|
|
|
|
|
2017-09-24 18:11:58 +00:00
|
|
|
for( const auto& duplicateName : duplicateSheetNames )
|
2017-11-17 17:00:04 +00:00
|
|
|
{
|
|
|
|
SCH_SHEET* renamedSheet = newScreen->GetSheet( duplicateName );
|
|
|
|
|
|
|
|
wxCHECK2_MSG( renamedSheet, continue,
|
|
|
|
"Sheet " + duplicateName + " not found in imported schematic." );
|
|
|
|
|
2017-12-07 08:29:10 +00:00
|
|
|
timestamp_t newtimestamp = GetNewTimeStamp();
|
2017-11-17 17:00:04 +00:00
|
|
|
renamedSheet->SetTimeStamp( newtimestamp );
|
2017-12-07 10:11:24 +00:00
|
|
|
renamedSheet->SetName( wxString::Format( "Sheet%8.8lX", (unsigned long) newtimestamp ) );
|
2017-11-17 17:00:04 +00:00
|
|
|
}
|
|
|
|
|
2018-04-29 14:08:23 +00:00
|
|
|
// It is finally safe to add the imported schematic.
|
2017-11-17 17:00:04 +00:00
|
|
|
screen->Append( newScreen );
|
|
|
|
|
|
|
|
SCH_SCREENS allScreens;
|
|
|
|
allScreens.ReplaceDuplicateTimeStamps();
|
|
|
|
|
2016-01-23 15:25:07 +00:00
|
|
|
OnModify();
|
2013-01-24 17:46:37 +00:00
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
SCH_SCREENS screens( GetCurrentSheet().Last() );
|
|
|
|
screens.UpdateSymbolLinks( true );
|
2018-04-29 14:08:23 +00:00
|
|
|
|
|
|
|
// Clear all annotation in the imported schematic to prevent clashes with existing annotation.
|
|
|
|
// Must be done after updating the symbol links as we need to know about multi-unit parts.
|
|
|
|
screens.ClearAnnotation();
|
|
|
|
|
2013-01-24 17:46:37 +00:00
|
|
|
GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
SetSheetNumberAndCount();
|
|
|
|
m_canvas->Refresh( true );
|
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 ) )
|
|
|
|
OnSaveProject( event );
|
|
|
|
}
|
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() );
|
|
|
|
|
|
|
|
wxFileDialog dlg( this, _( "Import Schematic" ), path,
|
2017-11-12 00:31:38 +00:00
|
|
|
wxEmptyString, EagleSchematicFileWildcard(),
|
2017-09-20 14:20:38 +00:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2017-12-12 14:28:21 +00:00
|
|
|
if( setProject )
|
|
|
|
{
|
|
|
|
wxFileName projectFn( dlg.GetPath() );
|
|
|
|
projectFn.SetExt( ProjectFileExtension );
|
|
|
|
Prj().SetProjectFullName( projectFn.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
2017-09-20 14:20:38 +00:00
|
|
|
// For now there is only one import plugin
|
2018-02-26 10:34:36 +00:00
|
|
|
importFile( dlg.GetPath(), SCH_IO_MGR::SCH_EAGLE );
|
2017-09-20 14:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
void SCH_EDIT_FRAME::OnSaveProject( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREEN* screen;
|
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_SCREENS screenList;
|
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.
|
|
|
|
wxString fileName = Prj().AbsolutePath( g_RootSheet->GetFileName() );
|
2013-05-07 18:32:06 +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
|
|
|
wxFileName fn = fileName;
|
2011-08-18 19:25:12 +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( !fn.IsDirWritable() )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
wxString 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 );
|
2011-08-18 19:25:12 +00:00
|
|
|
return;
|
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
|
|
|
|
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
|
|
|
for( screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
|
2012-09-28 17:47:41 +00:00
|
|
|
SaveEEFile( screen );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-01-21 19:58:02 +00:00
|
|
|
CreateArchiveLibraryCacheFile();
|
2013-02-01 07:58:49 +00:00
|
|
|
|
|
|
|
UpdateTitle();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2011-10-15 13:25:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::doAutoSave()
|
|
|
|
{
|
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 tmpFileName = g_RootSheet->GetFileName();
|
|
|
|
wxFileName fn = tmpFileName;
|
2011-10-15 13:25:57 +00:00
|
|
|
wxFileName tmp;
|
|
|
|
SCH_SCREENS screens;
|
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;
|
|
|
|
|
|
|
|
tmp.AssignDir( fn.GetPath() );
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
|
2011-10-15 13:25:57 +00:00
|
|
|
{
|
|
|
|
// Only create auto save files for the schematics that have been modified.
|
|
|
|
if( !screen->IsSave() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tmpFileName = fn = screen->GetFileName();
|
|
|
|
|
2015-05-03 13:48:05 +00:00
|
|
|
// Auto save file name is the normal file name prefixed with AUTOSAVE_PREFIX_FILENAME.
|
|
|
|
fn.SetName( AUTOSAVE_PREFIX_FILENAME + fn.GetName() );
|
2011-10-15 13:25:57 +00:00
|
|
|
|
|
|
|
screen->SetFileName( fn.GetFullPath() );
|
|
|
|
|
2012-09-28 17:47:41 +00:00
|
|
|
if( SaveEEFile( screen, false, NO_BACKUP_FILE ) )
|
2011-10-15 13:25:57 +00:00
|
|
|
screen->SetModify();
|
|
|
|
else
|
|
|
|
autoSaveOk = false;
|
|
|
|
|
|
|
|
screen->SetFileName( tmpFileName.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( autoSaveOk )
|
|
|
|
m_autoSaveState = false;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
wxString fullFileName( aFileName );
|
|
|
|
wxString projectpath;
|
|
|
|
wxFileName newfilename;
|
|
|
|
SCH_SHEET_LIST sheetList( g_RootSheet );
|
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
|
|
|
{
|
|
|
|
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( fullFileName ).IsAbsolute(),
|
|
|
|
wxT( "Import eagle schematic caller didn't send full filename" ) );
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
if( !LockFile( fullFileName ) )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
wxString msg = wxString::Format( _( "Schematic file \"%s\" is already open." ),
|
2017-10-03 10:30:23 +00:00
|
|
|
GetChars( fullFileName ) );
|
2017-10-03 10:23:52 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2017-09-20 14:28:49 +00:00
|
|
|
try
|
|
|
|
{
|
2018-02-28 15:43:33 +00:00
|
|
|
delete g_RootSheet;
|
|
|
|
g_RootSheet = nullptr;
|
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ) );
|
2017-09-20 14:28:49 +00:00
|
|
|
g_RootSheet = pi->Load( fullFileName, &Kiway() );
|
|
|
|
|
2018-02-28 15:43:33 +00:00
|
|
|
|
|
|
|
// Eagle sheets do not use a worksheet frame by default, so set it to an empty one
|
|
|
|
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
|
|
|
|
pglayout.SetEmptyLayout();
|
|
|
|
|
|
|
|
BASE_SCREEN::m_PageLayoutDescrFileName = "empty.kicad_wks";
|
|
|
|
wxFileName layoutfn( Kiway().Prj().GetProjectPath(),
|
|
|
|
BASE_SCREEN::m_PageLayoutDescrFileName );
|
|
|
|
wxFile layoutfile;
|
|
|
|
|
|
|
|
if( layoutfile.Create( layoutfn.GetFullPath() ) )
|
|
|
|
{
|
|
|
|
layoutfile.Write( WORKSHEET_LAYOUT::EmptyLayout() );
|
|
|
|
layoutfile.Close();
|
|
|
|
}
|
|
|
|
|
2017-09-20 14:28:49 +00:00
|
|
|
projectpath = Kiway().Prj().GetProjectPath();
|
2018-03-03 13:34:46 +00:00
|
|
|
newfilename.SetPath( Prj().GetProjectPath() );
|
|
|
|
newfilename.SetName( Prj().GetProjectName() );
|
2017-09-20 14:28:49 +00:00
|
|
|
newfilename.SetExt( SchematicFileExtension );
|
|
|
|
|
|
|
|
m_CurrentSheet->clear();
|
|
|
|
m_CurrentSheet->push_back( g_RootSheet );
|
|
|
|
SetScreen( m_CurrentSheet->LastScreen() );
|
|
|
|
|
|
|
|
g_RootSheet->SetFileName( newfilename.GetFullPath() );
|
|
|
|
GetScreen()->SetFileName( newfilename.GetFullPath() );
|
|
|
|
GetScreen()->SetModify();
|
2018-04-20 08:03:21 +00:00
|
|
|
SaveProjectSettings( false );
|
2017-09-20 14:28:49 +00:00
|
|
|
|
|
|
|
UpdateFileHistory( fullFileName );
|
2018-02-28 15:43:33 +00:00
|
|
|
SCH_SCREENS schematic;
|
|
|
|
schematic.UpdateSymbolLinks(); // Update all symbol library links for all sheets.
|
2017-11-27 19:27:24 +00:00
|
|
|
|
|
|
|
// Ensure the schematic is fully segmented on first display
|
|
|
|
BreakSegmentsOnJunctions();
|
|
|
|
SchematicCleanUp( true );
|
2018-02-27 16:05:46 +00:00
|
|
|
|
2018-02-28 10:31:02 +00:00
|
|
|
|
2018-02-27 16:05:46 +00:00
|
|
|
SCH_TYPE_COLLECTOR components;
|
2018-02-28 10:31:02 +00:00
|
|
|
SCH_SCREENS allScreens;
|
|
|
|
for( SCH_SCREEN* screen = allScreens.GetFirst(); screen; screen = allScreens.GetNext() )
|
2018-02-27 16:05:46 +00:00
|
|
|
{
|
2018-02-28 10:31:02 +00:00
|
|
|
components.Collect( screen->GetDrawItems(), SCH_COLLECTOR::ComponentsOnly );
|
2018-02-27 16:05:46 +00:00
|
|
|
|
2018-02-28 10:31:02 +00:00
|
|
|
for( int cmpIdx = 0; cmpIdx < components.GetCount(); ++cmpIdx )
|
2018-02-27 16:05:46 +00:00
|
|
|
{
|
2018-02-28 10:31:02 +00:00
|
|
|
std::vector<wxPoint> pts;
|
|
|
|
SCH_COMPONENT* cmp = static_cast<SCH_COMPONENT*>( components[cmpIdx] );
|
|
|
|
|
|
|
|
// Update footprint LIB_ID to point to the imported Eagle library
|
|
|
|
auto fpField = cmp->GetField( FOOTPRINT );
|
|
|
|
|
|
|
|
if( !fpField->GetText().IsEmpty() )
|
|
|
|
{
|
|
|
|
LIB_ID fpId( fpField->GetText() );
|
|
|
|
fpId.SetLibNickname( newfilename.GetName() );
|
|
|
|
fpField->SetText( fpId.Format() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add junction dots where necessary
|
|
|
|
cmp->GetConnectionPoints( pts );
|
|
|
|
|
|
|
|
for( auto i = pts.begin(); i != pts.end(); ++i )
|
|
|
|
{
|
|
|
|
if( GetScreen()->IsJunctionNeeded( *i, true ) )
|
|
|
|
AddJunction( *i, true );
|
|
|
|
}
|
2018-02-27 16:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-28 10:31:02 +00:00
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 );
|
2018-03-03 13:34:46 +00:00
|
|
|
// Only perform the dangling end test on root sheet.
|
|
|
|
GetScreen()->TestDanglingEnds();
|
2017-09-20 14:28:49 +00:00
|
|
|
|
|
|
|
GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
SetSheetNumberAndCount();
|
|
|
|
m_canvas->Refresh( true );
|
|
|
|
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();
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
|
|
|
|
wxString msg;
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Error loading schematic file \"%s\".\n%s" ),
|
2017-11-17 17:00:04 +00:00
|
|
|
fullFileName, ioe.What() );
|
2017-09-20 14:28:49 +00:00
|
|
|
DisplayError( this, msg );
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Failed to load \"%s\"" ), fullFileName );
|
2017-09-20 14:28:49 +00:00
|
|
|
AppendMsgPanel( wxEmptyString, msg, CYAN );
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2017-09-20 14:28:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
return true;
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-24 15:56:15 +00:00
|
|
|
|
2017-10-03 10:23:52 +00:00
|
|
|
return false;
|
2017-08-24 15:56:15 +00:00
|
|
|
}
|
2017-09-20 14:20:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::AskToSaveChanges()
|
|
|
|
{
|
|
|
|
SCH_SCREENS screenList;
|
|
|
|
|
|
|
|
// Save any currently open and modified project files.
|
|
|
|
for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
|
|
|
|
{
|
|
|
|
if( screen->IsModify() )
|
|
|
|
{
|
|
|
|
int response = YesNoCancelDialog( m_parent, _(
|
|
|
|
"The current schematic has been modified. Do you wish to save the changes?" ),
|
|
|
|
wxEmptyString,
|
|
|
|
_( "Save and Load" ),
|
|
|
|
_( "Load Without Saving" )
|
|
|
|
);
|
|
|
|
|
|
|
|
if( response == wxID_CANCEL )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if( response == wxID_YES )
|
|
|
|
{
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
OnSaveProject( dummy );
|
|
|
|
}
|
|
|
|
// else wxID_NO, so do not save
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|