2011-10-27 13:34:28 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-04-26 16:32:16 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2019-04-18 15:45:10 +00:00
|
|
|
* Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors.
|
2011-10-27 13:34:28 +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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2015-06-07 20:31:55 +00:00
|
|
|
#include <kiface_i.h>
|
2017-11-17 17:00:04 +00:00
|
|
|
#include <project.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
2019-06-19 10:31:21 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-05-28 18:44:14 +00:00
|
|
|
#include <wx/clipbrd.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2017-11-17 17:00:04 +00:00
|
|
|
#include <sch_legacy_plugin.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_sheet.h>
|
2015-06-07 20:31:55 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_view.h>
|
2019-07-29 19:59:31 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialogs/dialog_sch_sheet_props.h>
|
2019-08-22 09:49:35 +00:00
|
|
|
#include <dialogs/dialog_edit_sheet_pin.h>
|
2019-06-19 10:31:21 +00:00
|
|
|
#include <tool/actions.h>
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2019-07-29 19:59:31 +00:00
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::checkSheetForRecursion( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy )
|
|
|
|
{
|
|
|
|
wxASSERT( aSheet && aHierarchy );
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
SCH_SHEET_LIST hierarchy( g_RootSheet ); // This is the full schematic sheet hierarchy.
|
|
|
|
SCH_SHEET_LIST sheetHierarchy( aSheet ); // This is the hierarchy of the loaded file.
|
|
|
|
|
|
|
|
wxFileName destFile = aHierarchy->LastScreen()->GetFileName();
|
|
|
|
|
|
|
|
// SCH_SCREEN object file paths are expected to be absolute. If this assert fires,
|
|
|
|
// something is seriously broken.
|
|
|
|
wxASSERT( destFile.IsAbsolute() );
|
|
|
|
|
2019-08-13 20:33:57 +00:00
|
|
|
if( hierarchy.TestForRecursion( sheetHierarchy, destFile.GetFullPath() ) )
|
2019-07-29 19:59:31 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "The sheet changes cannot be made because the destination sheet already "
|
|
|
|
"has the sheet \"%s\" or one of it's subsheets as a parent somewhere in "
|
|
|
|
"the schematic hierarchy." ),
|
|
|
|
destFile.GetFullPath() );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::checkForNoFullyDefinedLibIds( SCH_SHEET* aSheet )
|
|
|
|
{
|
|
|
|
wxASSERT( aSheet && aSheet->GetScreen() );
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
SCH_SCREENS newScreens( aSheet );
|
|
|
|
|
|
|
|
if( newScreens.HasNoFullyDefinedLibIds() )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "The schematic \"%s\" has not had it's symbol library links remapped "
|
|
|
|
"to the symbol library table. The project this schematic belongs to "
|
|
|
|
"must first be remapped before it can be imported into the current "
|
|
|
|
"project." ), aSheet->GetScreen()->GetFileName() );
|
|
|
|
DisplayInfoMessage( this, msg );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-31 22:03:27 +00:00
|
|
|
void SCH_EDIT_FRAME::InitSheet( SCH_SHEET* aSheet, const wxString& aNewFilename )
|
2019-05-03 11:49:59 +00:00
|
|
|
{
|
|
|
|
aSheet->SetScreen( new SCH_SCREEN( &Kiway() ) );
|
|
|
|
aSheet->GetScreen()->SetModify();
|
|
|
|
aSheet->GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
|
2019-05-31 22:03:27 +00:00
|
|
|
aSheet->GetScreen()->SetFileName( aNewFilename );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-29 19:59:31 +00:00
|
|
|
bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy,
|
|
|
|
const wxString& aFileName )
|
2019-05-31 22:03:27 +00:00
|
|
|
{
|
2019-07-29 19:59:31 +00:00
|
|
|
wxASSERT( aSheet && aHierarchy );
|
|
|
|
|
|
|
|
int i;
|
|
|
|
wxString msg;
|
|
|
|
wxString topLevelSheetPath;
|
|
|
|
wxFileName tmp;
|
|
|
|
wxFileName currentSheetFileName;
|
|
|
|
bool libTableChanged = false;
|
|
|
|
SCH_SCREEN* currentScreen = aHierarchy->LastScreen();
|
2019-05-31 22:03:27 +00:00
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
|
2019-07-29 19:59:31 +00:00
|
|
|
std::unique_ptr< SCH_SHEET> newSheet( new SCH_SHEET );
|
2019-05-31 22:03:27 +00:00
|
|
|
|
2019-07-29 19:59:31 +00:00
|
|
|
wxFileName fileName( aFileName );
|
2019-05-31 22:03:27 +00:00
|
|
|
|
|
|
|
if( !fileName.IsAbsolute() )
|
|
|
|
{
|
2019-07-29 19:59:31 +00:00
|
|
|
wxCHECK_MSG( fileName.MakeAbsolute(), false,
|
|
|
|
wxString::Format( "Cannot make file name \"%s\" path absolute.",
|
|
|
|
aFileName ) );
|
2019-05-31 22:03:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString fullFilename = fileName.GetFullPath();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2019-07-29 19:59:31 +00:00
|
|
|
if( aSheet->GetScreen() != nullptr )
|
|
|
|
{
|
|
|
|
newSheet.reset( pi->Load( fullFilename, &Kiway() ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newSheet->SetFileName( fullFilename );
|
|
|
|
pi->Load( fullFilename, &Kiway(), newSheet.get() );
|
|
|
|
}
|
2019-05-31 22:03:27 +00:00
|
|
|
|
|
|
|
if( !pi->GetError().IsEmpty() )
|
|
|
|
{
|
2019-07-29 19:59:31 +00:00
|
|
|
msg = _( "The entire schematic could not be loaded. Errors occurred attempting "
|
|
|
|
"to load hierarchical sheet schematics." );
|
|
|
|
|
|
|
|
wxMessageDialog msgDlg1( this, msg, _( "Schematic Load Error" ),
|
|
|
|
wxOK | wxCANCEL | wxCANCEL_DEFAULT |
|
|
|
|
wxCENTER | wxICON_QUESTION );
|
|
|
|
msgDlg1.SetOKLabel( wxMessageDialog::ButtonLabel( _( "Use partial schematic" ) ) );
|
|
|
|
msgDlg1.SetExtendedMessage( pi->GetError() );
|
|
|
|
|
|
|
|
if( msgDlg1.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
2019-05-31 22:03:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Error occurred loading schematic file \"%s\"." ), fullFilename );
|
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
|
|
|
|
|
|
|
msg.Printf( _( "Failed to load schematic \"%s\"" ), fullFilename );
|
|
|
|
AppendMsgPanel( wxEmptyString, msg, CYAN );
|
|
|
|
|
2019-07-29 19:59:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = fileName;
|
|
|
|
|
|
|
|
// If the loaded schematic is in a different folder from the current project and
|
|
|
|
// it contains hierarchical sheets, the hierarchical sheet paths need to be updated.
|
|
|
|
if( fileName.GetPath( wxPATH_GET_SEPARATOR ) != Prj().GetProjectPath()
|
|
|
|
&& newSheet->CountSheets() )
|
|
|
|
{
|
|
|
|
// Give the user the option to choose relative path if possible.
|
|
|
|
if( tmp.MakeRelativeTo( Prj().GetProjectPath() ) )
|
|
|
|
{
|
|
|
|
wxMessageDialog msgDlg2(
|
|
|
|
this,
|
|
|
|
"Do you want to use a relative path to the loaded "
|
|
|
|
"schematic?", "Select Path Type",
|
|
|
|
wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
|
|
|
|
msgDlg2.SetYesNoLabels( wxMessageDialog::ButtonLabel( "Use Relative Path" ),
|
|
|
|
wxMessageDialog::ButtonLabel( "Use Absolute Path" ) );
|
|
|
|
int rsp = msgDlg2.ShowModal();
|
|
|
|
|
|
|
|
if( rsp == wxID_CANCEL )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if( rsp == wxID_NO )
|
|
|
|
{
|
|
|
|
topLevelSheetPath = fileName.GetPathWithSep();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-13 20:33:57 +00:00
|
|
|
topLevelSheetPath = tmp.GetPathWithSep();
|
2019-07-29 19:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
topLevelSheetPath = tmp.GetPathWithSep();
|
|
|
|
}
|
2019-08-13 20:33:57 +00:00
|
|
|
|
|
|
|
if( wxFileName::GetPathSeparator() == '\\' )
|
|
|
|
topLevelSheetPath.Replace( "\\", "/" );
|
2019-05-31 22:03:27 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 19:59:31 +00:00
|
|
|
// 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 loaded file.
|
|
|
|
|
|
|
|
if( checkSheetForRecursion( newSheet.get(), aHierarchy )
|
|
|
|
|| checkForNoFullyDefinedLibIds( newSheet.get() ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Make a valiant attempt to warn the user of all possible scenarios where there could
|
|
|
|
// be broken symbol library links.
|
|
|
|
wxArrayString names;
|
|
|
|
wxArrayString newLibNames;
|
|
|
|
SCH_SCREENS newScreens( newSheet.get() ); // All screens associated with the import.
|
|
|
|
SCH_SCREENS prjScreens( g_RootSheet );
|
|
|
|
|
|
|
|
newScreens.GetLibNicknames( names );
|
|
|
|
|
|
|
|
wxMessageDialog::ButtonLabel okButtonLabel( _( "Continue Load" ) );
|
|
|
|
wxMessageDialog::ButtonLabel cancelButtonLabel( _( "Cancel Load" ) );
|
|
|
|
|
|
|
|
if( fileName.GetPath( wxPATH_GET_SEPARATOR ) == Prj().GetProjectPath()
|
|
|
|
&& !prjScreens.HasSchematic( fullFilename ) )
|
|
|
|
{
|
|
|
|
// A schematic in the current project path that isn't part of the current project.
|
|
|
|
// It's possible the user copied this schematic from another project so the library
|
|
|
|
// links may not be avaible. Even this is check is no guarantee that all symbol
|
|
|
|
// library links are valid but it's better than nothing.
|
|
|
|
for( const auto& name : names )
|
|
|
|
{
|
|
|
|
if( !Prj().SchSymbolLibTable()->HasLibrary( name ) )
|
|
|
|
newLibNames.Add( name );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !newLibNames.IsEmpty() )
|
|
|
|
{
|
|
|
|
msg = _( "There are library names in the loaded schematic that are missing "
|
|
|
|
"from the project library table. This may result in broken symbol "
|
|
|
|
"library links for the loaded schematic. Do you wish to continue?" );
|
|
|
|
wxMessageDialog msgDlg3( this, msg, _( "Continue Load Schematic" ),
|
|
|
|
wxOK | wxCANCEL | wxCANCEL_DEFAULT |
|
|
|
|
wxCENTER | wxICON_QUESTION );
|
|
|
|
msgDlg3.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
|
|
|
|
|
|
|
|
if( msgDlg3.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( fileName.GetPath( wxPATH_GET_SEPARATOR ) != Prj().GetProjectPath() )
|
|
|
|
{
|
|
|
|
// A schematic loaded from a path other than the current project path.
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
wxArrayString duplicateLibNames;
|
|
|
|
|
|
|
|
for( const auto& name : names )
|
|
|
|
{
|
|
|
|
if( !Prj().SchSymbolLibTable()->HasLibrary( name ) )
|
|
|
|
newLibNames.Add( name );
|
|
|
|
else
|
|
|
|
duplicateLibNames.Add( name );
|
|
|
|
}
|
2019-05-31 22:03:27 +00:00
|
|
|
|
2019-07-29 19:59:31 +00:00
|
|
|
SYMBOL_LIB_TABLE table;
|
|
|
|
wxFileName symLibTableFn( fileName.GetPath(),
|
|
|
|
SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
|
|
|
|
|
|
|
|
// If there are any new or duplicate libraries, check to see if it's possible that
|
|
|
|
// there could be any missing libraries that would cause broken symbol library links.
|
|
|
|
if( !newLibNames.IsEmpty() || !duplicateLibNames.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( !symLibTableFn.Exists() || !symLibTableFn.IsFileReadable() )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "The project library table \"%s\" does not exist or cannot "
|
|
|
|
"be read. This may result in broken symbol links for the "
|
|
|
|
"schematic. Do you wish to continue?" ),
|
|
|
|
fileName.GetFullPath() );
|
|
|
|
wxMessageDialog msgDlg4( this, msg, _( "Continue Load Schematic" ),
|
|
|
|
wxOK | wxCANCEL | wxCANCEL_DEFAULT |
|
|
|
|
wxCENTER | wxICON_QUESTION );
|
|
|
|
msgDlg4.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
|
|
|
|
|
|
|
|
if( msgDlg4.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
table.Load( symLibTableFn.GetFullPath() );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "An error occurred loading the symbol library table "
|
|
|
|
"\"%s\"." ),
|
|
|
|
symLibTableFn.GetFullPath() );
|
|
|
|
DisplayErrorMessage( NULL, msg, ioe.What() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if any of the symbol libraries found in the appended schematic do
|
|
|
|
// not exist in the current project are missing from the appended project symbol
|
|
|
|
// library table.
|
|
|
|
if( !newLibNames.IsEmpty() )
|
|
|
|
{
|
|
|
|
bool missingLibNames = table.IsEmpty();
|
|
|
|
|
|
|
|
if( !missingLibNames )
|
|
|
|
{
|
|
|
|
for( const auto& newLibName : newLibNames )
|
|
|
|
{
|
|
|
|
if( !table.HasLibrary( newLibName ) )
|
|
|
|
{
|
|
|
|
missingLibNames = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( missingLibNames )
|
|
|
|
{
|
|
|
|
msg = _( "There are library names in the loaded schematic that are missing "
|
|
|
|
"from the loaded schematic project library table. This may result "
|
|
|
|
"in broken symbol library links for the schematic. "
|
|
|
|
"Do you wish to continue?" );
|
|
|
|
wxMessageDialog msgDlg5( this, msg, _( "Continue Load Schematic" ),
|
|
|
|
wxOK | wxCANCEL | wxCANCEL_DEFAULT |
|
|
|
|
wxCENTER | wxICON_QUESTION );
|
|
|
|
msgDlg5.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
|
|
|
|
|
|
|
|
if( msgDlg5.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The library name already exists in the current project. Check to see if the
|
|
|
|
// duplicate name is the same library in the current project. If it's not, it's
|
|
|
|
// most likely that the symbol library links will be broken.
|
|
|
|
if( !duplicateLibNames.IsEmpty() && !table.IsEmpty() )
|
|
|
|
{
|
|
|
|
bool libNameConflict = false;
|
|
|
|
|
|
|
|
for( const auto& duplicateLibName : duplicateLibNames )
|
|
|
|
{
|
|
|
|
const SYMBOL_LIB_TABLE_ROW* thisRow = nullptr;
|
|
|
|
const SYMBOL_LIB_TABLE_ROW* otherRow = nullptr;
|
|
|
|
|
|
|
|
if( Prj().SchSymbolLibTable()->HasLibrary( duplicateLibName ) )
|
|
|
|
thisRow = Prj().SchSymbolLibTable()->FindRow( duplicateLibName );
|
|
|
|
|
|
|
|
if( table.HasLibrary( duplicateLibName ) )
|
|
|
|
otherRow = table.FindRow( duplicateLibName );
|
|
|
|
|
|
|
|
// It's in the global library table so there is no conflict.
|
|
|
|
if( thisRow && !otherRow )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !thisRow || !otherRow )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxFileName otherUriFileName;
|
|
|
|
wxString thisURI = thisRow->GetFullURI( true );
|
|
|
|
wxString otherURI = otherRow->GetFullURI( false);
|
|
|
|
|
|
|
|
if( otherURI.Contains( "${KIPRJMOD}" ) || otherURI.Contains( "$(KIPRJMOD)" ) )
|
|
|
|
{
|
|
|
|
// Cannot use relative paths here, "${KIPRJMOD}../path-to-cache-lib" does
|
|
|
|
// not expand to a valid symbol library path.
|
|
|
|
otherUriFileName.SetPath( fileName.GetPath() );
|
|
|
|
otherUriFileName.SetFullName( otherURI.AfterLast( '}' ) );
|
|
|
|
otherURI = otherUriFileName.GetFullPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( thisURI != otherURI )
|
|
|
|
{
|
|
|
|
libNameConflict = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( libNameConflict )
|
|
|
|
{
|
|
|
|
msg = _( "A duplicate library name that references a different library exists "
|
|
|
|
"in the current library table. This conflict cannot be resolved and "
|
|
|
|
"may result in broken symbol library links for the schematic. "
|
|
|
|
"Do you wish to continue?" );
|
|
|
|
wxMessageDialog msgDlg6( this, msg, _( "Continue Load Schematic" ),
|
|
|
|
wxOK | wxCANCEL | wxCANCEL_DEFAULT |
|
|
|
|
wxCENTER | wxICON_QUESTION );
|
|
|
|
msgDlg6.SetOKCancelLabels( okButtonLabel, cancelButtonLabel );
|
|
|
|
|
|
|
|
if( msgDlg6.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// All (most?) of the possible broken symbol library link cases are covered. Map the
|
|
|
|
// new appended schematic project symbol library table entries to the current project
|
|
|
|
// symbol library table.
|
|
|
|
if( !newLibNames.IsEmpty() && !table.IsEmpty() )
|
|
|
|
{
|
|
|
|
for( const auto& libName : newLibNames )
|
|
|
|
{
|
|
|
|
if( !table.HasLibrary( libName )
|
|
|
|
|| Prj().SchSymbolLibTable()->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}" ) || uri.Contains( "$(KIPRJMOD)" ) )
|
|
|
|
{
|
|
|
|
// Cannot use relative paths here, "${KIPRJMOD}../path-to-cache-lib" does
|
|
|
|
// not expand to a valid symbol library path.
|
|
|
|
newLib.SetPath( fileName.GetPath() );
|
|
|
|
newLib.SetFullName( uri.AfterLast( '}' ) );
|
|
|
|
uri = newLib.GetFullPath();
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
|
|
|
|
auto newRow = new SYMBOL_LIB_TABLE_ROW( libName, uri, row->GetType(),
|
2019-08-13 20:33:57 +00:00
|
|
|
row->GetOptions(), row->GetDescr() );
|
2019-07-29 19:59:31 +00:00
|
|
|
|
|
|
|
Prj().SchSymbolLibTable()->InsertRow( newRow );
|
|
|
|
libTableChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for duplicate sheet names in the current page.
|
|
|
|
wxArrayString duplicateSheetNames;
|
|
|
|
EE_TYPE_COLLECTOR sheets;
|
|
|
|
|
|
|
|
sheets.Collect( currentScreen->GetDrawItems(), EE_COLLECTOR::SheetsOnly );
|
|
|
|
|
|
|
|
for( 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rename all duplicate sheet names.
|
|
|
|
SCH_SCREEN* newScreen = newSheet->GetScreen();
|
|
|
|
wxCHECK_MSG( newScreen, false, "No screen defined for sheet." );
|
|
|
|
|
|
|
|
for( const auto& duplicateName : duplicateSheetNames )
|
|
|
|
{
|
|
|
|
SCH_SHEET* renamedSheet = newScreen->GetSheet( duplicateName );
|
|
|
|
|
|
|
|
wxCHECK2_MSG( renamedSheet, continue,
|
|
|
|
"Sheet " + duplicateName + " not found in imported schematic." );
|
|
|
|
|
|
|
|
timestamp_t newtimestamp = GetNewTimeStamp();
|
|
|
|
renamedSheet->SetTimeStamp( newtimestamp );
|
|
|
|
renamedSheet->SetName( wxString::Format( "Sheet%8.8lX", (unsigned long) newtimestamp ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set all sheets loaded into the correct sheet file paths.
|
|
|
|
EE_TYPE_COLLECTOR newTopLevelSheets;
|
|
|
|
|
|
|
|
newTopLevelSheets.Collect( newSheet->GetScreen()->GetDrawItems(), EE_COLLECTOR::SheetsOnly );
|
|
|
|
|
|
|
|
for( i = 0; i < newTopLevelSheets.GetCount(); ++i )
|
|
|
|
{
|
|
|
|
SCH_SHEET* tmpSheet = dynamic_cast< SCH_SHEET* >( newTopLevelSheets[i] );
|
|
|
|
wxCHECK2( tmpSheet != nullptr, continue );
|
|
|
|
tmpSheet->SetFileName( topLevelSheetPath + tmpSheet->GetFileName() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( libTableChanged )
|
|
|
|
Prj().SchSymbolLibTable()->Save( Prj().GetProjectPath() +
|
|
|
|
SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
|
|
|
|
|
|
|
|
// It is finally safe to add or append the imported schematic.
|
|
|
|
if( aSheet->GetScreen() == nullptr )
|
|
|
|
aSheet->SetScreen( newScreen );
|
|
|
|
else
|
|
|
|
aSheet->GetScreen()->Append( newScreen );
|
|
|
|
|
|
|
|
SCH_SCREENS allScreens;
|
|
|
|
allScreens.ReplaceDuplicateTimeStamps();
|
|
|
|
|
|
|
|
SCH_SCREENS screens( aSheet );
|
|
|
|
screens.UpdateSymbolLinks( true );
|
|
|
|
|
|
|
|
return true;
|
2019-05-03 11:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-24 19:37:32 +00:00
|
|
|
bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy,
|
|
|
|
bool* aClearAnnotationNewItems )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2015-06-07 20:31:55 +00:00
|
|
|
if( aSheet == NULL || aHierarchy == NULL )
|
2009-12-15 21:11:05 +00:00
|
|
|
return false;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-08-05 21:02:41 +00:00
|
|
|
// Get the new texts
|
2018-02-02 15:56:09 +00:00
|
|
|
DIALOG_SCH_SHEET_PROPS dlg( this, aSheet );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxFileName fileName = dlg.GetFileName();
|
|
|
|
fileName.SetExt( SchematicFileExtension );
|
|
|
|
|
|
|
|
wxString msg;
|
2019-07-29 19:59:31 +00:00
|
|
|
bool renameFile = false;
|
2011-01-20 16:34:57 +00:00
|
|
|
bool loadFromFile = false;
|
2018-04-18 00:07:51 +00:00
|
|
|
bool clearAnnotation = false;
|
2019-07-29 19:59:31 +00:00
|
|
|
bool restoreSheet = false;
|
|
|
|
bool isExistingSheet = false;
|
2011-01-20 16:34:57 +00:00
|
|
|
SCH_SCREEN* useScreen = NULL;
|
|
|
|
|
2018-02-05 14:01:55 +00:00
|
|
|
// Relative file names are relative to the path of the current sheet. This allows for
|
|
|
|
// nesting of schematic files in subfolders.
|
|
|
|
if( !fileName.IsAbsolute() )
|
|
|
|
{
|
|
|
|
const SCH_SCREEN* currentScreen = aHierarchy->LastScreen();
|
|
|
|
|
|
|
|
wxCHECK_MSG( currentScreen, false, "Invalid sheet path object." );
|
|
|
|
|
|
|
|
wxFileName currentSheetFileName = currentScreen->GetFileName();
|
|
|
|
|
|
|
|
wxCHECK_MSG( fileName.Normalize( wxPATH_NORM_ALL, currentSheetFileName.GetPath() ), false,
|
|
|
|
"Cannot normalize new sheet schematic file path." );
|
|
|
|
}
|
|
|
|
|
2019-08-13 20:33:57 +00:00
|
|
|
wxString newFilename = fileName.GetFullPath();
|
2014-11-02 13:17:48 +00:00
|
|
|
|
2019-06-26 01:44:00 +00:00
|
|
|
// Search for a schematic file having the same filename already in use in the hierarchy
|
|
|
|
// or on disk, in order to reuse it.
|
2018-02-05 14:01:55 +00:00
|
|
|
if( !g_RootSheet->SearchHierarchy( newFilename, &useScreen ) )
|
2014-11-02 13:17:48 +00:00
|
|
|
{
|
2017-11-17 17:00:04 +00:00
|
|
|
loadFromFile = wxFileExists( newFilename );
|
2018-02-02 15:56:09 +00:00
|
|
|
wxLogDebug( "Sheet requested file \"%s\", %s",
|
|
|
|
newFilename,
|
|
|
|
( loadFromFile ) ? "found" : "not found" );
|
2014-11-02 13:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inside Eeschema, filenames are stored using unix notation
|
2015-06-07 20:31:55 +00:00
|
|
|
newFilename.Replace( wxT( "\\" ), wxT( "/" ) );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2019-07-29 19:59:31 +00:00
|
|
|
if( aSheet->GetScreen() == NULL ) // New sheet.
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2019-11-17 16:43:05 +00:00
|
|
|
if( !allowCaseSensitiveFileNameClashes( newFilename ) )
|
|
|
|
return false;
|
|
|
|
|
2019-07-29 19:59:31 +00:00
|
|
|
if( useScreen || loadFromFile ) // Load from existing file.
|
2011-01-20 16:34:57 +00:00
|
|
|
{
|
2018-04-18 00:07:51 +00:00
|
|
|
clearAnnotation = true;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2018-04-18 00:07:51 +00:00
|
|
|
wxString existsMsg;
|
|
|
|
wxString linkMsg;
|
|
|
|
existsMsg.Printf( _( "\"%s\" already exists." ), fileName.GetFullName() );
|
|
|
|
linkMsg.Printf( _( "Link \"%s\" to this file?" ), dlg.GetSheetName() );
|
|
|
|
msg.Printf( wxT( "%s\n\n%s" ), existsMsg, linkMsg );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return false;
|
2018-04-18 00:07:51 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
}
|
2019-07-29 19:59:31 +00:00
|
|
|
else // New file.
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2019-05-03 11:49:59 +00:00
|
|
|
InitSheet( aSheet, newFilename );
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
}
|
2019-07-29 19:59:31 +00:00
|
|
|
else // Existing sheet.
|
2011-01-20 16:34:57 +00:00
|
|
|
{
|
|
|
|
bool isUndoable = true;
|
2018-04-18 00:07:51 +00:00
|
|
|
wxString replaceMsg;
|
|
|
|
wxString newMsg;
|
|
|
|
wxString noUndoMsg;
|
|
|
|
|
2019-07-29 19:59:31 +00:00
|
|
|
isExistingSheet = true;
|
|
|
|
|
2019-11-17 16:43:05 +00:00
|
|
|
if( !allowCaseSensitiveFileNameClashes( newFilename ) )
|
|
|
|
return false;
|
|
|
|
|
2018-06-23 14:54:51 +00:00
|
|
|
// Changing the filename of a sheet can modify the full hierarchy structure
|
|
|
|
// and can be not always undoable.
|
|
|
|
// So prepare messages for user notifications:
|
2018-04-18 00:07:51 +00:00
|
|
|
replaceMsg.Printf( _( "Change \"%s\" link from \"%s\" to \"%s\"?" ),
|
|
|
|
dlg.GetSheetName(), aSheet->GetFileName(), fileName.GetFullName() );
|
|
|
|
newMsg.Printf( _( "Create new file \"%s\" with contents of \"%s\"?" ),
|
|
|
|
fileName.GetFullName(), aSheet->GetFileName() );
|
|
|
|
noUndoMsg = _( "This action cannot be undone." );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
// We are always using here a case insensitive comparison
|
|
|
|
// to avoid issues under Windows, although under Unix
|
|
|
|
// filenames are case sensitive.
|
|
|
|
// But many users create schematic under both Unix and Windows
|
2018-03-29 20:48:14 +00:00
|
|
|
// **
|
2018-06-23 14:54:51 +00:00
|
|
|
// N.B. 1: aSheet->GetFileName() will return a relative path
|
|
|
|
// aSheet->GetScreen()->GetFileName() returns a full path
|
|
|
|
//
|
|
|
|
// N.B. 2: newFilename uses the unix notation for separator.
|
|
|
|
// so we must use it also to compare the old filename to the new filename
|
|
|
|
wxString oldFilename = aSheet->GetScreen()->GetFileName();
|
|
|
|
oldFilename.Replace( wxT( "\\" ), wxT( "/" ) );
|
|
|
|
|
2019-11-17 16:43:05 +00:00
|
|
|
if( newFilename.Cmp( oldFilename ) != 0 )
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
// Sheet file name changes cannot be undone.
|
|
|
|
isUndoable = false;
|
|
|
|
|
2019-07-29 19:59:31 +00:00
|
|
|
if( useScreen || loadFromFile ) // Load from existing file.
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2018-04-18 00:07:51 +00:00
|
|
|
clearAnnotation = true;
|
2015-06-07 20:31:55 +00:00
|
|
|
|
2018-04-18 00:07:51 +00:00
|
|
|
msg.Printf( wxT( "%s\n\n%s" ), replaceMsg, noUndoMsg );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( loadFromFile )
|
|
|
|
aSheet->SetScreen( NULL );
|
|
|
|
}
|
2019-07-29 19:59:31 +00:00
|
|
|
else // Save to new file name.
|
2011-01-20 16:34:57 +00:00
|
|
|
{
|
|
|
|
if( aSheet->GetScreenCount() > 1 )
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2018-04-18 00:07:51 +00:00
|
|
|
msg.Printf( wxT( "%s\n\n%s" ), newMsg, noUndoMsg );
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2018-04-18 00:07:51 +00:00
|
|
|
if( !IsOK( this, msg ) )
|
2011-01-20 16:34:57 +00:00
|
|
|
return false;
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
|
|
|
|
renameFile = true;
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
}
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( isUndoable )
|
|
|
|
SaveCopyInUndoList( aSheet, UR_CHANGED );
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( renameFile )
|
|
|
|
{
|
2019-05-31 22:03:27 +00:00
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
|
|
|
|
|
2018-05-29 17:57:18 +00:00
|
|
|
// If the the associated screen is shared by more than one sheet, do not
|
|
|
|
// change the filename of the corresponding screen here.
|
|
|
|
// (a new screen will be created later)
|
|
|
|
// if it is not shared, update the filename
|
|
|
|
if( aSheet->GetScreenCount() <= 1 )
|
|
|
|
aSheet->GetScreen()->SetFileName( newFilename );
|
2017-11-17 17:00:04 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
pi->Save( newFilename, aSheet->GetScreen(), &Kiway() );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Error occurred saving schematic file \"%s\"." ), newFilename );
|
2017-11-17 17:00:04 +00:00
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Failed to save schematic \"%s\"" ), newFilename );
|
2017-11-17 17:00:04 +00:00
|
|
|
AppendMsgPanel( wxEmptyString, msg, CYAN );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
// If the the associated screen is shared by more than one sheet, remove the
|
|
|
|
// screen and reload the file to a new screen. Failure to do this will trash
|
|
|
|
// the screen reference counting in complex hierarchies.
|
|
|
|
if( aSheet->GetScreenCount() > 1 )
|
2009-12-15 21:11:05 +00:00
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
aSheet->SetScreen( NULL );
|
|
|
|
loadFromFile = true;
|
2009-12-15 21:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2018-02-05 14:01:55 +00:00
|
|
|
wxFileName userFileName = dlg.GetFileName();
|
2018-02-20 21:01:52 +00:00
|
|
|
userFileName.SetExt( SchematicFileExtension );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
|
|
|
if( useScreen )
|
2017-11-17 17:00:04 +00:00
|
|
|
{
|
2019-07-29 19:59:31 +00:00
|
|
|
// Create a temporary sheet for recursion testing to prevent a possible recursion error.
|
|
|
|
std::unique_ptr< SCH_SHEET> tmpSheet( new SCH_SHEET );
|
|
|
|
tmpSheet->SetName( dlg.GetSheetName() );
|
2019-08-13 20:33:57 +00:00
|
|
|
tmpSheet->SetFileName( userFileName.GetFullPath() );
|
2019-07-29 19:59:31 +00:00
|
|
|
tmpSheet->SetScreen( useScreen );
|
|
|
|
|
|
|
|
// No need to check for valid library IDs if we are using an existing screen.
|
|
|
|
if( checkSheetForRecursion( tmpSheet.get(), aHierarchy ) )
|
|
|
|
{
|
|
|
|
if( restoreSheet )
|
|
|
|
aHierarchy->LastScreen()->Append( aSheet );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's safe to set the sheet screen now.
|
2011-01-20 16:34:57 +00:00
|
|
|
aSheet->SetScreen( useScreen );
|
2017-11-17 17:00:04 +00:00
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
else if( loadFromFile )
|
2017-11-17 17:00:04 +00:00
|
|
|
{
|
2019-07-29 19:59:31 +00:00
|
|
|
if( isExistingSheet )
|
|
|
|
{
|
|
|
|
// Temporarily remove the sheet from the current schematic page so that recursion
|
|
|
|
// and symbol library link tests can be performed with the modified sheet settings.
|
|
|
|
restoreSheet = true;
|
|
|
|
aHierarchy->LastScreen()->Remove( aSheet );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !LoadSheetFromFile( aSheet, aHierarchy, newFilename ) )
|
|
|
|
{
|
|
|
|
if( restoreSheet )
|
|
|
|
aHierarchy->LastScreen()->Append( aSheet );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( restoreSheet )
|
|
|
|
aHierarchy->LastScreen()->Append( aSheet );
|
2017-11-17 17:00:04 +00:00
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2019-08-13 20:33:57 +00:00
|
|
|
wxString tmpFn = userFileName.GetFullPath();
|
|
|
|
|
|
|
|
if( wxFileName::GetPathSeparator() == '\\' )
|
|
|
|
tmpFn.Replace( "\\", "/" );
|
|
|
|
|
|
|
|
aSheet->SetFileName( tmpFn );
|
2018-02-02 15:56:09 +00:00
|
|
|
aSheet->SetFileNameSize( dlg.GetFileNameTextSize() );
|
2011-12-08 15:45:01 +00:00
|
|
|
aSheet->SetName( dlg.GetSheetName() );
|
2018-02-02 15:56:09 +00:00
|
|
|
aSheet->SetSheetNameSize( dlg.GetSheetNameTextSize() );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( aSheet->GetName().IsEmpty() )
|
2015-04-23 19:43:45 +00:00
|
|
|
aSheet->SetName( wxString::Format( wxT( "Sheet%8.8lX" ),
|
|
|
|
(long unsigned) aSheet->GetTimeStamp() ) );
|
2009-06-11 14:26:17 +00:00
|
|
|
|
2018-09-03 10:11:39 +00:00
|
|
|
if( aClearAnnotationNewItems )
|
|
|
|
*aClearAnnotationNewItems = clearAnnotation;
|
2018-04-18 00:07:51 +00:00
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
GetCanvas()->GetView()->Update( aSheet );
|
|
|
|
|
2011-10-27 13:34:28 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-01 13:24:51 +00:00
|
|
|
PINSHEETLABEL_SHAPE SCH_EDIT_FRAME::m_lastSheetPinType = NET_INPUT;
|
|
|
|
wxSize SCH_EDIT_FRAME::m_lastSheetPinTextSize( -1, -1 );
|
|
|
|
wxPoint SCH_EDIT_FRAME::m_lastSheetPinPosition;
|
|
|
|
|
|
|
|
const wxSize &SCH_EDIT_FRAME::GetLastSheetPinTextSize()
|
|
|
|
{
|
|
|
|
// Delayed initialization (need the preferences to be loaded)
|
|
|
|
if( m_lastSheetPinTextSize.x == -1 )
|
|
|
|
{
|
|
|
|
m_lastSheetPinTextSize.x = GetDefaultTextSize();
|
|
|
|
m_lastSheetPinTextSize.y = GetDefaultTextSize();
|
|
|
|
}
|
|
|
|
return m_lastSheetPinTextSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-16 21:58:47 +00:00
|
|
|
SCH_SHEET_PIN* SCH_EDIT_FRAME::CreateSheetPin( SCH_SHEET* aSheet, SCH_HIERLABEL* aLabel )
|
2019-05-01 13:24:51 +00:00
|
|
|
{
|
2019-05-16 21:58:47 +00:00
|
|
|
wxString text;
|
2019-05-01 13:24:51 +00:00
|
|
|
SCH_SHEET_PIN* sheetPin;
|
|
|
|
|
2019-05-16 21:58:47 +00:00
|
|
|
if( aLabel )
|
|
|
|
{
|
|
|
|
text = aLabel->GetText();
|
|
|
|
m_lastSheetPinType = aLabel->GetShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), text );
|
2019-05-01 13:24:51 +00:00
|
|
|
sheetPin->SetFlags( IS_NEW );
|
|
|
|
sheetPin->SetTextSize( GetLastSheetPinTextSize() );
|
|
|
|
sheetPin->SetShape( m_lastSheetPinType );
|
|
|
|
|
2019-05-16 21:58:47 +00:00
|
|
|
if( !aLabel )
|
2019-05-01 13:24:51 +00:00
|
|
|
{
|
2019-08-22 09:49:35 +00:00
|
|
|
DIALOG_EDIT_SHEET_PIN dlg( this, sheetPin );
|
2019-05-16 21:58:47 +00:00
|
|
|
|
2019-06-19 10:31:21 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK || sheetPin->GetText().IsEmpty() )
|
2019-05-16 21:58:47 +00:00
|
|
|
{
|
|
|
|
delete sheetPin;
|
2019-06-13 13:34:38 +00:00
|
|
|
return nullptr;
|
2019-05-16 21:58:47 +00:00
|
|
|
}
|
2019-05-01 13:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_lastSheetPinType = sheetPin->GetShape();
|
|
|
|
m_lastSheetPinTextSize = sheetPin->GetTextSize();
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
sheetPin->SetPosition( (wxPoint) GetCanvas()->GetViewControls()->GetCursorPosition() );
|
2019-05-01 13:24:51 +00:00
|
|
|
|
|
|
|
return sheetPin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-16 21:58:47 +00:00
|
|
|
SCH_HIERLABEL* SCH_EDIT_FRAME::ImportHierLabel( SCH_SHEET* aSheet )
|
2019-05-01 13:24:51 +00:00
|
|
|
{
|
|
|
|
if( !aSheet->GetScreen() )
|
|
|
|
return NULL;
|
|
|
|
|
2019-05-16 21:58:47 +00:00
|
|
|
for( EDA_ITEM* item = aSheet->GetScreen()->GetDrawItems(); item != NULL; item = item->Next() )
|
2019-05-01 13:24:51 +00:00
|
|
|
{
|
|
|
|
if( item->Type() != SCH_HIER_LABEL_T )
|
|
|
|
continue;
|
|
|
|
|
2019-05-16 21:58:47 +00:00
|
|
|
SCH_HIERLABEL* label = (SCH_HIERLABEL*) item;
|
2019-05-01 13:24:51 +00:00
|
|
|
|
|
|
|
/* A global label has been found: check if there a corresponding sheet label. */
|
|
|
|
if( !aSheet->HasPin( label->GetText() ) )
|
2019-05-16 21:58:47 +00:00
|
|
|
return label;
|
2019-05-01 13:24:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 21:58:47 +00:00
|
|
|
return nullptr;
|
2019-05-01 13:24:51 +00:00
|
|
|
}
|
2019-05-28 18:44:14 +00:00
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
void SCH_EDIT_FRAME::DrawCurrentSheetToClipboard()
|
2019-05-28 18:44:14 +00:00
|
|
|
{
|
|
|
|
wxRect DrawArea;
|
2019-05-31 17:37:07 +00:00
|
|
|
BASE_SCREEN* screen = GetScreen();
|
2019-05-28 18:44:14 +00:00
|
|
|
|
|
|
|
DrawArea.SetSize( GetPageSizeIU() );
|
|
|
|
|
|
|
|
// Calculate a reasonable dc size, in pixels, and the dc scale to fit
|
|
|
|
// the drawings into the dc size
|
|
|
|
// scale is the ratio resolution (in PPI) / internal units
|
|
|
|
double ppi = 300; // Use 300 pixels per inch to create bitmap images on start
|
|
|
|
double inch2Iu = 1000.0 * IU_PER_MILS;
|
|
|
|
double scale = ppi / inch2Iu;
|
|
|
|
|
|
|
|
wxSize dcsize = DrawArea.GetSize();
|
|
|
|
|
|
|
|
int maxdim = std::max( dcsize.x, dcsize.y );
|
|
|
|
|
|
|
|
// the max size in pixels of the bitmap used to byuild the sheet copy
|
|
|
|
const int maxbitmapsize = 3000;
|
|
|
|
|
|
|
|
while( int( maxdim * scale ) > maxbitmapsize )
|
|
|
|
{
|
|
|
|
ppi = ppi / 1.5;
|
|
|
|
scale = ppi / inch2Iu;
|
|
|
|
}
|
|
|
|
|
|
|
|
dcsize.x *= scale;
|
|
|
|
dcsize.y *= scale;
|
|
|
|
|
|
|
|
// Set draw offset, zoom... to values needed to draw in the memory DC
|
|
|
|
// after saving initial values:
|
|
|
|
wxPoint tmp_startvisu = screen->m_StartVisu;
|
|
|
|
double tmpzoom = screen->GetZoom();
|
|
|
|
wxPoint old_org = screen->m_DrawOrg;
|
|
|
|
screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0;
|
|
|
|
screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
|
|
|
|
|
|
|
|
screen->SetZoom( 1 ); // we use zoom = 1 in draw functions.
|
|
|
|
|
|
|
|
wxMemoryDC dc;
|
|
|
|
wxBitmap image( dcsize );
|
|
|
|
dc.SelectObject( image );
|
|
|
|
|
|
|
|
GRResetPenAndBrush( &dc );
|
|
|
|
GRForceBlackPen( false );
|
|
|
|
screen->m_IsPrinting = true;
|
|
|
|
dc.SetUserScale( scale, scale );
|
|
|
|
|
|
|
|
dc.Clear();
|
2019-06-01 19:48:01 +00:00
|
|
|
PrintPage( &dc );
|
2019-05-28 18:44:14 +00:00
|
|
|
screen->m_IsPrinting = false;
|
|
|
|
|
|
|
|
if( wxTheClipboard->Open() )
|
|
|
|
{
|
|
|
|
// This data objects are held by the clipboard, so do not delete them in the app.
|
|
|
|
wxBitmapDataObject* clipbrd_data = new wxBitmapDataObject( image );
|
|
|
|
wxTheClipboard->SetData( clipbrd_data );
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deselect Bitmap from DC in order to delete the MemoryDC
|
|
|
|
dc.SelectObject( wxNullBitmap );
|
|
|
|
|
|
|
|
GRForceBlackPen( false );
|
|
|
|
|
|
|
|
screen->m_StartVisu = tmp_startvisu;
|
|
|
|
screen->m_DrawOrg = old_org;
|
|
|
|
screen->SetZoom( tmpzoom );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-17 16:43:05 +00:00
|
|
|
bool SCH_EDIT_FRAME::allowCaseSensitiveFileNameClashes( const wxString& aSchematicFileName )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
SCH_SCREENS screens;
|
|
|
|
wxFileName fn = aSchematicFileName;
|
|
|
|
|
|
|
|
wxCHECK( fn.IsAbsolute(), false );
|
|
|
|
|
|
|
|
if( m_showSheetFileNameCaseSensitivityDlg
|
|
|
|
&& screens.CanCauseCaseSensitivityIssue( aSchematicFileName ) )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "The file name \"%s\" can cause issues with an existing file name\n"
|
|
|
|
"already defined in the schematic on systems that support case\n"
|
|
|
|
"insensitive file names. This will cause issues if you copy this\n"
|
|
|
|
"project to an operating system that supports case insensitive file\n"
|
|
|
|
"names.\n\nDo you wish to continue?" ),
|
|
|
|
fn.GetName() );
|
|
|
|
|
|
|
|
wxRichMessageDialog dlg( this, msg, _( "Warning" ),
|
|
|
|
wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION );
|
|
|
|
dlg.ShowCheckBox( _( "Do not show this message again." ) );
|
|
|
|
dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Create New Sheet" ) ),
|
|
|
|
wxMessageDialog::ButtonLabel( _( "Discard New Sheet" ) ) );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_NO )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_showSheetFileNameCaseSensitivityDlg = !dlg.IsCheckBoxChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|