2014-10-21 15:48:00 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-03-16 13:04:50 +00:00
|
|
|
* Copyright (C) 2009 Wayne Stambaugh <stambaughw@gmail.com>
|
2024-02-17 13:50:22 +00:00
|
|
|
* Copyright (C) 2014-2024 KiCad Developers, see CHANGELOG.txt for contributors.
|
2014-10-21 15:48:00 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
#include <dialog_sheet_properties.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2019-02-23 13:58:57 +00:00
|
|
|
#include <wx/string.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2020-03-06 20:02:58 +00:00
|
|
|
#include <wx/tooltip.h>
|
2023-03-12 14:49:57 +00:00
|
|
|
#include <common.h>
|
2019-02-23 13:58:57 +00:00
|
|
|
#include <confirm.h>
|
2014-08-24 22:49:31 +00:00
|
|
|
#include <validators.h>
|
2022-08-14 17:36:40 +00:00
|
|
|
#include <wx_filename.h>
|
2018-02-02 15:56:09 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2021-12-16 14:39:58 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2024-04-11 14:11:02 +00:00
|
|
|
#include <sch_commit.h>
|
2019-02-23 13:58:57 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_sheet.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2019-08-25 23:45:10 +00:00
|
|
|
#include <bitmaps.h>
|
2020-03-06 20:02:58 +00:00
|
|
|
#include <eeschema_settings.h>
|
2020-03-08 02:18:45 +00:00
|
|
|
#include <settings/color_settings.h>
|
2020-04-26 20:53:29 +00:00
|
|
|
#include <trace_helpers.h>
|
2020-04-09 16:15:57 +00:00
|
|
|
#include "panel_eeschema_color_settings.h"
|
2022-04-30 12:37:40 +00:00
|
|
|
#include "wx/dcclient.h"
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_SHEET* aSheet,
|
2024-03-17 13:02:07 +00:00
|
|
|
bool* aClearAnnotationNewItems,
|
|
|
|
bool* aUpdateHierarchyNavigator ) :
|
2020-10-06 13:23:10 +00:00
|
|
|
DIALOG_SHEET_PROPERTIES_BASE( aParent ),
|
2020-03-06 20:02:58 +00:00
|
|
|
m_frame( aParent ),
|
2020-03-08 02:18:45 +00:00
|
|
|
m_clearAnnotationNewItems( aClearAnnotationNewItems ),
|
2024-03-17 13:02:07 +00:00
|
|
|
m_updateHierarchyNavigator( aUpdateHierarchyNavigator ),
|
2021-03-12 15:12:49 +00:00
|
|
|
m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits ),
|
2020-11-18 17:54:41 +00:00
|
|
|
m_dummySheet( *aSheet ),
|
2023-02-19 03:40:07 +00:00
|
|
|
m_dummySheetNameField( VECTOR2I( -1, -1 ), SHEETNAME, &m_dummySheet )
|
2012-10-13 18:54:33 +00:00
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
m_sheet = aSheet;
|
2024-04-12 21:00:41 +00:00
|
|
|
m_fields = new FIELDS_GRID_TABLE( this, aParent, m_grid, m_sheet );
|
2020-03-06 20:02:58 +00:00
|
|
|
m_delayedFocusRow = SHEETNAME;
|
|
|
|
m_delayedFocusColumn = FDC_VALUE;
|
2019-08-25 23:45:10 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
// Give a bit more room for combobox editors
|
|
|
|
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
|
2020-02-20 21:29:21 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
m_grid->SetTable( m_fields );
|
2023-03-02 17:50:39 +00:00
|
|
|
m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this,
|
|
|
|
[&]( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
OnAddField( aEvent );
|
|
|
|
} ) );
|
2021-12-12 17:27:40 +00:00
|
|
|
m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
2020-02-20 21:29:21 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
// Show/hide columns according to user's preference
|
2023-04-13 12:45:22 +00:00
|
|
|
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
2020-03-21 16:31:48 +00:00
|
|
|
{
|
2023-04-13 12:45:22 +00:00
|
|
|
m_grid->ShowHideColumns( cfg->m_Appearance.edit_sheet_visible_columns );
|
|
|
|
m_shownColumns = m_grid->GetShownColumns();
|
2020-03-21 16:31:48 +00:00
|
|
|
}
|
2019-02-23 13:58:57 +00:00
|
|
|
|
2022-03-29 19:41:03 +00:00
|
|
|
if( m_frame->GetColorSettings()->GetOverrideSchItemColors() )
|
|
|
|
m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
|
|
|
|
|
2022-12-16 22:48:36 +00:00
|
|
|
wxSize minSize = m_pageNumberTextCtrl->GetMinSize();
|
|
|
|
int minWidth = m_pageNumberTextCtrl->GetTextExtent( wxT( "XXX.XXX" ) ).GetWidth();
|
|
|
|
|
|
|
|
m_pageNumberTextCtrl->SetMinSize( wxSize( minWidth, minSize.GetHeight() ) );
|
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
wxToolTip::Enable( true );
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
// Configure button logos
|
2023-10-21 18:56:19 +00:00
|
|
|
m_bpAdd->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
|
|
|
|
m_bpDelete->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
|
|
|
|
m_bpMoveUp->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
|
|
|
|
m_bpMoveDown->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2020-03-13 17:28:17 +00:00
|
|
|
// Set font sizes
|
2021-09-11 19:07:33 +00:00
|
|
|
m_hierarchicalPathLabel->SetFont( KIUI::GetInfoFont( this ) );
|
2022-04-30 12:37:40 +00:00
|
|
|
m_hierarchicalPath->SetFont( KIUI::GetInfoFont( this ) );
|
2020-03-13 17:28:17 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
// wxFormBuilder doesn't include this event...
|
|
|
|
m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
|
2020-10-06 13:17:45 +00:00
|
|
|
wxGridEventHandler( DIALOG_SHEET_PROPERTIES::OnGridCellChanging ),
|
2021-05-27 18:36:47 +00:00
|
|
|
nullptr, this );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
2018-02-02 15:56:09 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
DIALOG_SHEET_PROPERTIES::~DIALOG_SHEET_PROPERTIES()
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2023-04-13 12:45:22 +00:00
|
|
|
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
2022-12-24 22:18:05 +00:00
|
|
|
{
|
2023-04-13 12:45:22 +00:00
|
|
|
cfg->m_Appearance.edit_sheet_visible_columns = m_grid->GetShownColumnsAsString();
|
2022-12-24 22:18:05 +00:00
|
|
|
cfg->m_Appearance.edit_sheet_width = GetSize().x;
|
|
|
|
cfg->m_Appearance.edit_sheet_height = GetSize().y;
|
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
// Prevents crash bug in wxGrid's d'tor
|
|
|
|
m_grid->DestroyTable( m_fields );
|
|
|
|
|
|
|
|
m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
|
2020-10-06 13:17:45 +00:00
|
|
|
wxGridEventHandler( DIALOG_SHEET_PROPERTIES::OnGridCellChanging ),
|
2021-05-27 18:36:47 +00:00
|
|
|
nullptr, this );
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_grid->PopEventHandler( true );
|
2012-10-13 18:54:33 +00:00
|
|
|
}
|
|
|
|
|
2014-08-24 22:49:31 +00:00
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
bool DIALOG_SHEET_PROPERTIES::TransferDataToWindow()
|
2012-10-13 18:54:33 +00:00
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
2020-04-01 14:00:40 +00:00
|
|
|
// Push a copy of each field into m_updateFields
|
2020-03-06 20:02:58 +00:00
|
|
|
for( SCH_FIELD& field : m_sheet->GetFields() )
|
|
|
|
{
|
|
|
|
SCH_FIELD field_copy( field );
|
2018-02-02 15:56:09 +00:00
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
#ifdef __WINDOWS__
|
2020-03-06 20:02:58 +00:00
|
|
|
// Filenames are stored using unix notation
|
|
|
|
if( field_copy.GetId() == SHEETFILENAME )
|
|
|
|
{
|
|
|
|
wxString filename = field_copy.GetText();
|
2021-05-27 18:36:47 +00:00
|
|
|
filename.Replace( wxT( "/" ), wxT( "\\" ) );
|
2020-03-06 20:02:58 +00:00
|
|
|
field_copy.SetText( filename );
|
|
|
|
}
|
2012-10-13 18:54:33 +00:00
|
|
|
#endif
|
2018-02-02 15:56:09 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
// change offset to be symbol-relative
|
|
|
|
field_copy.Offset( -m_sheet->GetPosition() );
|
|
|
|
|
|
|
|
m_fields->push_back( field_copy );
|
|
|
|
}
|
|
|
|
|
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->size() );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
2021-12-16 14:39:58 +00:00
|
|
|
AdjustGridColumns();
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2020-03-08 02:18:45 +00:00
|
|
|
// border width
|
|
|
|
m_borderWidth.SetValue( m_sheet->GetBorderWidth() );
|
|
|
|
|
|
|
|
// set up color swatches
|
2020-08-04 23:50:12 +00:00
|
|
|
KIGFX::COLOR4D borderColor = m_sheet->GetBorderColor();
|
|
|
|
KIGFX::COLOR4D backgroundColor = m_sheet->GetBackgroundColor();
|
2020-03-08 02:18:45 +00:00
|
|
|
|
2020-08-04 23:50:12 +00:00
|
|
|
m_borderSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
|
|
|
|
m_backgroundSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2020-04-09 16:15:57 +00:00
|
|
|
m_borderSwatch->SetSwatchColor( borderColor, false );
|
|
|
|
m_backgroundSwatch->SetSwatchColor( backgroundColor, false );
|
2020-03-08 02:18:45 +00:00
|
|
|
|
|
|
|
KIGFX::COLOR4D canvas = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
|
2020-04-09 16:15:57 +00:00
|
|
|
m_borderSwatch->SetSwatchBackground( canvas );
|
|
|
|
m_backgroundSwatch->SetSwatchBackground( canvas );
|
2020-03-08 02:18:45 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetFullHierarchy();
|
|
|
|
SCH_SHEET_PATH instance = m_frame->GetCurrentSheet();
|
|
|
|
|
2020-10-25 12:08:10 +00:00
|
|
|
instance.push_back( m_sheet );
|
|
|
|
|
2022-12-25 16:04:45 +00:00
|
|
|
wxString pageNumber;
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2022-12-25 16:04:45 +00:00
|
|
|
if( m_sheet->IsNew() )
|
|
|
|
{
|
|
|
|
// Don't try to be too clever when assigning the next availabe page number. Just use
|
|
|
|
// the number of sheets plus one.
|
|
|
|
pageNumber.Printf( wxT( "%d" ), static_cast<int>( hierarchy.size() ) + 1 );
|
|
|
|
instance.SetPageNumber( pageNumber );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pageNumber = instance.GetPageNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pageNumberTextCtrl->ChangeValue( pageNumber );
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
bool DIALOG_SHEET_PROPERTIES::Validate()
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
LIB_ID id;
|
|
|
|
|
|
|
|
if( !m_grid->CommitPendingChanges() || !m_grid->Validate() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check for missing field names.
|
|
|
|
for( size_t i = SHEET_MANDATORY_FIELDS; i < m_fields->size(); ++i )
|
|
|
|
{
|
|
|
|
SCH_FIELD& field = m_fields->at( i );
|
|
|
|
|
2023-09-12 22:20:25 +00:00
|
|
|
if( field.GetName( false ).empty() && !field.GetText().empty() )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
DisplayErrorMessage( this, _( "Fields must have a name." ) );
|
2018-02-02 15:56:09 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
m_delayedFocusColumn = FDC_NAME;
|
|
|
|
m_delayedFocusRow = i;
|
2018-02-02 15:56:09 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-03-05 12:20:38 +00:00
|
|
|
|
2018-02-02 15:56:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
static bool positioningChanged( const SCH_FIELD& a, const SCH_FIELD& b )
|
|
|
|
{
|
|
|
|
if( a.GetPosition() != b.GetPosition() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( a.GetHorizJustify() != b.GetHorizJustify() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( a.GetVertJustify() != b.GetVertJustify() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( a.GetTextAngle() != b.GetTextAngle() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
static bool positioningChanged( FIELDS_GRID_TABLE* a, std::vector<SCH_FIELD>& b )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2020-03-07 20:11:26 +00:00
|
|
|
for( size_t i = 0; i < SHEET_MANDATORY_FIELDS; ++i )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
if( positioningChanged( a->at( i ), b.at( i ) ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
bool DIALOG_SHEET_PROPERTIES::TransferDataFromWindow()
|
2018-02-02 15:56:09 +00:00
|
|
|
{
|
2024-04-11 14:11:02 +00:00
|
|
|
wxCHECK( m_sheet && m_frame, false );
|
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() ) // Calls our Validate() method.
|
|
|
|
return false;
|
|
|
|
|
2024-04-11 14:11:02 +00:00
|
|
|
SCH_COMMIT commit( m_frame );
|
|
|
|
|
|
|
|
commit.Modify( m_sheet, m_frame->GetScreen() );
|
|
|
|
|
|
|
|
bool isUndoable = true;
|
|
|
|
|
2021-05-27 18:36:47 +00:00
|
|
|
// Sheet file names can be relative or absolute.
|
|
|
|
wxString sheetFileName = m_fields->at( SHEETFILENAME ).GetText();
|
2020-04-01 16:30:05 +00:00
|
|
|
|
2020-04-22 20:00:48 +00:00
|
|
|
// Ensure filepath is not empty. (In normal use will be caught by grid validators,
|
|
|
|
// but unedited data from existing files can be bad.)
|
2021-05-27 18:36:47 +00:00
|
|
|
if( sheetFileName.IsEmpty() )
|
2020-04-01 16:30:05 +00:00
|
|
|
{
|
2021-05-27 18:36:47 +00:00
|
|
|
DisplayError( this, _( "A sheet must have a valid file name." ) );
|
2020-04-01 16:30:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-12 14:49:57 +00:00
|
|
|
// Ensure the filename extension is OK. (In normal use will be caught by grid validators,
|
|
|
|
// but unedited data from existing files can be bad.)
|
2023-12-28 02:10:01 +00:00
|
|
|
sheetFileName = EnsureFileExtension( sheetFileName, FILEEXT::KiCadSchematicFileExtension );
|
2020-04-01 16:30:05 +00:00
|
|
|
|
2023-03-12 14:49:57 +00:00
|
|
|
wxFileName fn( sheetFileName );
|
2020-04-01 16:30:05 +00:00
|
|
|
wxString newRelativeFilename = fn.GetFullPath();
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
// Inside Eeschema, filenames are stored using unix notation
|
|
|
|
newRelativeFilename.Replace( wxT( "\\" ), wxT( "/" ) );
|
2020-04-22 20:00:48 +00:00
|
|
|
|
2020-04-04 17:38:53 +00:00
|
|
|
wxString oldFilename = m_sheet->GetFields()[ SHEETFILENAME ].GetText();
|
|
|
|
oldFilename.Replace( wxT( "\\" ), wxT( "/" ) );
|
|
|
|
|
|
|
|
bool filename_changed = oldFilename != newRelativeFilename;
|
|
|
|
|
2020-06-02 19:27:39 +00:00
|
|
|
if( filename_changed || m_sheet->IsNew() )
|
2020-04-04 17:38:53 +00:00
|
|
|
{
|
2021-05-27 18:36:47 +00:00
|
|
|
SCH_SCREEN* currentScreen = m_frame->GetCurrentSheet().LastScreen();
|
|
|
|
|
|
|
|
wxCHECK( currentScreen, false );
|
|
|
|
|
|
|
|
bool clearFileName = false;
|
|
|
|
|
|
|
|
// This can happen for the root sheet when opening Eeschema in the stand alone mode.
|
|
|
|
if( currentScreen->GetFileName().IsEmpty() )
|
|
|
|
{
|
|
|
|
clearFileName = true;
|
|
|
|
currentScreen->SetFileName( m_frame->Prj().AbsolutePath( wxT( "noname.kicad_sch" ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFileName tmp( fn );
|
|
|
|
wxFileName screenFileName = currentScreen->GetFileName();
|
|
|
|
|
|
|
|
if( fn.IsAbsolute() && fn.MakeRelativeTo( screenFileName.GetPath() ) )
|
|
|
|
{
|
|
|
|
wxMessageDialog makeRelDlg( this, _( "Use relative path for sheet file?" ),
|
|
|
|
_( "Sheet File Path" ),
|
|
|
|
wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
|
|
|
|
|
2021-06-06 18:00:49 +00:00
|
|
|
makeRelDlg.SetExtendedMessage( _( "Using relative hierarchical sheet file name paths "
|
|
|
|
"improves schematic portability across systems and "
|
|
|
|
"platforms. Using absolute paths can result in "
|
|
|
|
"portability issues." ) );
|
2021-05-27 18:36:47 +00:00
|
|
|
makeRelDlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Use Relative Path" ) ),
|
|
|
|
wxMessageDialog::ButtonLabel( _( "Use Absolute Path" ) ) );
|
|
|
|
|
|
|
|
if( makeRelDlg.ShowModal() == wxID_YES )
|
|
|
|
{
|
2021-06-06 18:00:49 +00:00
|
|
|
wxLogTrace( tracePathsAndFiles, "\n Converted absolute path: '%s'"
|
|
|
|
"\n to relative path: '%s'",
|
|
|
|
tmp.GetPath(),
|
|
|
|
fn.GetPath() );
|
2021-05-27 18:36:47 +00:00
|
|
|
m_fields->at( SHEETFILENAME ).SetText( fn.GetFullPath() );
|
|
|
|
newRelativeFilename = fn.GetFullPath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-11 14:11:02 +00:00
|
|
|
if( !onSheetFilenameChanged( newRelativeFilename, &isUndoable ) )
|
2021-05-27 18:36:47 +00:00
|
|
|
{
|
|
|
|
if( clearFileName )
|
|
|
|
currentScreen->SetFileName( wxEmptyString );
|
|
|
|
|
2020-04-04 17:38:53 +00:00
|
|
|
return false;
|
2021-05-27 18:36:47 +00:00
|
|
|
}
|
2024-03-17 13:02:07 +00:00
|
|
|
else if( m_updateHierarchyNavigator )
|
|
|
|
{
|
|
|
|
*m_updateHierarchyNavigator = true;
|
|
|
|
}
|
2021-05-27 18:36:47 +00:00
|
|
|
|
|
|
|
if( clearFileName )
|
|
|
|
currentScreen->SetFileName( wxEmptyString );
|
2020-10-05 12:24:21 +00:00
|
|
|
|
|
|
|
// One last validity check (and potential repair) just to be sure to be sure
|
|
|
|
SCH_SHEET_LIST repairedList( &m_frame->Schematic().Root(), true );
|
2020-04-04 17:38:53 +00:00
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
wxString newSheetname = m_fields->at( SHEETNAME ).GetText();
|
|
|
|
|
2024-03-17 13:02:07 +00:00
|
|
|
if( ( newSheetname != m_sheet->GetName() ) && m_updateHierarchyNavigator )
|
|
|
|
*m_updateHierarchyNavigator = true;
|
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
if( newSheetname.IsEmpty() )
|
|
|
|
newSheetname = _( "Untitled Sheet" );
|
|
|
|
|
2020-04-04 17:38:53 +00:00
|
|
|
m_fields->at( SHEETNAME ).SetText( newSheetname );
|
|
|
|
|
|
|
|
// change all field positions from relative to absolute
|
|
|
|
for( unsigned i = 0; i < m_fields->size(); ++i )
|
|
|
|
m_fields->at( i ).Offset( m_sheet->GetPosition() );
|
|
|
|
|
|
|
|
if( positioningChanged( m_fields, m_sheet->GetFields() ) )
|
|
|
|
m_sheet->ClearFieldsAutoplaced();
|
|
|
|
|
2023-03-19 19:15:02 +00:00
|
|
|
for( int ii = m_fields->GetNumberRows() - 1; ii >= SHEET_MANDATORY_FIELDS; ii-- )
|
|
|
|
{
|
|
|
|
SCH_FIELD& field = m_fields->at( ii );
|
|
|
|
const wxString& fieldName = field.GetCanonicalName();
|
|
|
|
|
2023-09-12 22:20:25 +00:00
|
|
|
if( field.IsEmpty() )
|
2023-03-19 19:15:02 +00:00
|
|
|
m_fields->erase( m_fields->begin() + ii );
|
|
|
|
else if( fieldName.IsEmpty() )
|
|
|
|
field.SetName( _( "untitled" ) );
|
|
|
|
}
|
|
|
|
|
2020-04-04 17:38:53 +00:00
|
|
|
m_sheet->SetFields( *m_fields );
|
|
|
|
|
|
|
|
m_sheet->SetBorderWidth( m_borderWidth.GetValue() );
|
2020-04-09 16:15:57 +00:00
|
|
|
|
|
|
|
COLOR_SETTINGS* colorSettings = m_frame->GetColorSettings();
|
|
|
|
|
|
|
|
if( colorSettings->GetOverrideSchItemColors()
|
|
|
|
&& ( m_sheet->GetBorderColor() != m_borderSwatch->GetSwatchColor() ||
|
|
|
|
m_sheet->GetBackgroundColor() != m_backgroundSwatch->GetSwatchColor() ) )
|
|
|
|
{
|
|
|
|
wxPanel temp( this );
|
|
|
|
temp.Hide();
|
2021-08-29 23:33:08 +00:00
|
|
|
PANEL_EESCHEMA_COLOR_SETTINGS prefs( &temp );
|
2020-04-09 16:15:57 +00:00
|
|
|
wxString checkboxLabel = prefs.m_optOverrideColors->GetLabel();
|
|
|
|
|
|
|
|
KIDIALOG dlg( this, _( "Note: item colors are overridden in the current color theme." ),
|
|
|
|
KIDIALOG::KD_WARNING );
|
|
|
|
dlg.ShowDetailedText( wxString::Format( _( "To see individual item colors uncheck '%s'\n"
|
2023-01-16 20:58:42 +00:00
|
|
|
"in Preferences > Schematic Editor > Colors." ),
|
2020-04-09 16:15:57 +00:00
|
|
|
checkboxLabel ) );
|
|
|
|
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sheet->SetBorderColor( m_borderSwatch->GetSwatchColor() );
|
|
|
|
m_sheet->SetBackgroundColor( m_backgroundSwatch->GetSwatchColor() );
|
2020-04-04 17:38:53 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
SCH_SHEET_PATH instance = m_frame->GetCurrentSheet();
|
|
|
|
|
2020-10-25 11:32:01 +00:00
|
|
|
instance.push_back( m_sheet );
|
|
|
|
|
2022-11-22 19:35:27 +00:00
|
|
|
instance.SetPageNumber( m_pageNumberTextCtrl->GetValue() );
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2020-04-04 17:38:53 +00:00
|
|
|
m_frame->TestDanglingEnds();
|
2020-05-03 22:20:31 +00:00
|
|
|
|
|
|
|
// Refresh all sheets in case ordering changed.
|
|
|
|
for( SCH_ITEM* item : m_frame->GetScreen()->Items().OfType( SCH_SHEET_T ) )
|
2020-08-10 11:40:58 +00:00
|
|
|
m_frame->UpdateItem( item );
|
2020-05-03 22:20:31 +00:00
|
|
|
|
2024-04-11 14:11:02 +00:00
|
|
|
if( isUndoable )
|
|
|
|
{
|
|
|
|
commit.Push( _( "Edit Sheet Properties" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If we are renaming files, the undo/redo list becomes invalid and must be cleared.
|
|
|
|
m_frame->ClearUndoRedoList();
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
2020-04-04 17:38:53 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-11 14:11:02 +00:00
|
|
|
bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilename,
|
|
|
|
bool* aIsUndoable )
|
2020-04-04 17:38:53 +00:00
|
|
|
{
|
2024-04-11 14:11:02 +00:00
|
|
|
wxCHECK( aIsUndoable, false );
|
|
|
|
|
2023-03-12 14:49:57 +00:00
|
|
|
wxString msg;
|
2023-12-28 02:10:01 +00:00
|
|
|
wxFileName sheetFileName(
|
|
|
|
EnsureFileExtension( aNewFilename, FILEEXT::KiCadSchematicFileExtension ) );
|
2020-04-26 20:53:29 +00:00
|
|
|
|
2021-05-27 18:36:47 +00:00
|
|
|
// Sheet file names are relative to the path of the current sheet. This allows for
|
|
|
|
// nesting of schematic files in subfolders. Screen file names are always absolute.
|
2022-06-12 14:46:11 +00:00
|
|
|
SCHEMATIC& schematic = m_frame->Schematic();
|
|
|
|
SCH_SHEET_LIST fullHierarchy = schematic.GetFullHierarchy();
|
|
|
|
wxFileName screenFileName( sheetFileName );
|
|
|
|
wxFileName tmp( sheetFileName );
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2021-05-27 18:36:47 +00:00
|
|
|
SCH_SCREEN* currentScreen = m_frame->GetCurrentSheet().LastScreen();
|
2020-04-22 20:00:48 +00:00
|
|
|
|
2021-05-27 18:36:47 +00:00
|
|
|
wxCHECK( currentScreen, false );
|
|
|
|
|
|
|
|
// SCH_SCREEN file names are always absolute.
|
|
|
|
wxFileName currentScreenFileName = currentScreen->GetFileName();
|
|
|
|
|
2022-08-14 17:36:40 +00:00
|
|
|
if( !screenFileName.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS,
|
|
|
|
currentScreenFileName.GetPath() ) )
|
2021-05-27 18:36:47 +00:00
|
|
|
{
|
2021-06-06 18:00:49 +00:00
|
|
|
msg = wxString::Format( _( "Cannot normalize new sheet schematic file path:\n"
|
|
|
|
"'%s'\n"
|
|
|
|
"against parent sheet schematic file path:\n"
|
|
|
|
"'%s'." ),
|
|
|
|
sheetFileName.GetPath(),
|
|
|
|
currentScreenFileName.GetPath() );
|
2021-05-27 18:36:47 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
|
2021-05-27 18:36:47 +00:00
|
|
|
wxString newAbsoluteFilename = screenFileName.GetFullPath();
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
// Inside Eeschema, filenames are stored using unix notation
|
|
|
|
newAbsoluteFilename.Replace( wxT( "\\" ), wxT( "/" ) );
|
|
|
|
|
|
|
|
bool renameFile = false;
|
|
|
|
bool loadFromFile = false;
|
|
|
|
bool clearAnnotation = false;
|
|
|
|
bool isExistingSheet = false;
|
2021-05-27 18:36:47 +00:00
|
|
|
SCH_SCREEN* useScreen = nullptr;
|
2021-11-23 18:55:01 +00:00
|
|
|
SCH_SCREEN* oldScreen = nullptr;
|
2020-03-06 20:02:58 +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.
|
2022-06-12 14:46:11 +00:00
|
|
|
if( !schematic.Root().SearchHierarchy( newAbsoluteFilename, &useScreen ) )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
loadFromFile = wxFileExists( newAbsoluteFilename );
|
2020-04-26 20:53:29 +00:00
|
|
|
|
2021-06-06 18:00:49 +00:00
|
|
|
wxLogTrace( tracePathsAndFiles, "\n Sheet requested file '%s', %s",
|
|
|
|
newAbsoluteFilename,
|
|
|
|
loadFromFile ? "found" : "not found" );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
|
2021-05-27 18:36:47 +00:00
|
|
|
if( m_sheet->GetScreen() == nullptr ) // New just created sheet.
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
if( !m_frame->AllowCaseSensitiveFileNameClashes( newAbsoluteFilename ) )
|
|
|
|
return false;
|
|
|
|
|
2020-04-04 17:38:53 +00:00
|
|
|
if( useScreen || loadFromFile ) // Load from existing file.
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
clearAnnotation = true;
|
|
|
|
|
2021-06-06 18:00:49 +00:00
|
|
|
if( !IsOK( this, wxString::Format( _( "'%s' already exists." ),
|
|
|
|
sheetFileName.GetFullName() )
|
|
|
|
+ wxT( "\n\n" )
|
|
|
|
+ wxString::Format( _( "Link '%s' to this file?" ),
|
|
|
|
newAbsoluteFilename ) ) )
|
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
return false;
|
2021-06-06 18:00:49 +00:00
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
2020-04-04 17:38:53 +00:00
|
|
|
else // New file.
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
m_frame->InitSheet( m_sheet, newAbsoluteFilename );
|
|
|
|
}
|
|
|
|
}
|
2020-04-04 17:38:53 +00:00
|
|
|
else // Existing sheet.
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
isExistingSheet = true;
|
|
|
|
|
|
|
|
if( !m_frame->AllowCaseSensitiveFileNameClashes( newAbsoluteFilename ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// **
|
|
|
|
// 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 and new filenames
|
|
|
|
wxString oldAbsoluteFilename = m_sheet->GetScreen()->GetFileName();
|
|
|
|
oldAbsoluteFilename.Replace( wxT( "\\" ), wxT( "/" ) );
|
|
|
|
|
|
|
|
if( newAbsoluteFilename.Cmp( oldAbsoluteFilename ) != 0 )
|
|
|
|
{
|
|
|
|
// Sheet file name changes cannot be undone.
|
2024-04-11 14:11:02 +00:00
|
|
|
*aIsUndoable = false;
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
if( useScreen || loadFromFile ) // Load from existing file.
|
|
|
|
{
|
|
|
|
clearAnnotation = true;
|
|
|
|
|
2021-06-06 18:00:49 +00:00
|
|
|
if( !IsOK( this, wxString::Format( _( "Change '%s' link from '%s' to '%s'?" ),
|
|
|
|
newAbsoluteFilename,
|
|
|
|
m_sheet->GetFileName(),
|
|
|
|
sheetFileName.GetFullName() )
|
|
|
|
+ wxT( "\n\n" )
|
|
|
|
+ _( "This action cannot be undone." ) ) )
|
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
return false;
|
2021-06-06 18:00:49 +00:00
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
if( loadFromFile )
|
2021-05-27 18:36:47 +00:00
|
|
|
m_sheet->SetScreen( nullptr );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
else // Save to new file name.
|
|
|
|
{
|
|
|
|
if( m_sheet->GetScreenCount() > 1 )
|
|
|
|
{
|
2022-04-08 16:05:27 +00:00
|
|
|
if( !IsOK( this, wxString::Format( _( "Create new file '%s' with contents "
|
|
|
|
"of '%s'?" ),
|
2021-06-06 18:00:49 +00:00
|
|
|
sheetFileName.GetFullName(),
|
|
|
|
m_sheet->GetFileName() )
|
|
|
|
+ wxT( "\n\n" )
|
|
|
|
+ _( "This action cannot be undone." ) ) )
|
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
return false;
|
2021-06-06 18:00:49 +00:00
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renameFile = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( renameFile )
|
|
|
|
{
|
2023-12-27 20:39:29 +00:00
|
|
|
IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// If the associated screen is shared by more than one sheet, do not
|
2020-03-06 20:02:58 +00:00
|
|
|
// change the filename of the corresponding screen here.
|
|
|
|
// (a new screen will be created later)
|
|
|
|
// if it is not shared, update the filename
|
|
|
|
if( m_sheet->GetScreenCount() <= 1 )
|
|
|
|
m_sheet->GetScreen()->SetFileName( newAbsoluteFilename );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2023-08-26 19:28:53 +00:00
|
|
|
pi->SaveSchematicFile( newAbsoluteFilename, m_sheet, &schematic );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2021-06-06 18:00:49 +00:00
|
|
|
msg = wxString::Format( _( "Error occurred saving schematic file '%s'." ),
|
|
|
|
newAbsoluteFilename );
|
2020-03-06 20:02:58 +00:00
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
|
|
|
|
2021-06-06 18:00:49 +00:00
|
|
|
msg = wxString::Format( _( "Failed to save schematic '%s'" ),
|
|
|
|
newAbsoluteFilename );
|
2020-12-08 05:34:36 +00:00
|
|
|
m_frame->SetMsgPanel( wxEmptyString, msg );
|
2020-03-06 20:02:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// If the associated screen is shared by more than one sheet, remove the
|
2020-03-06 20:02:58 +00:00
|
|
|
// screen and reload the file to a new screen. Failure to do this will trash
|
|
|
|
// the screen reference counting in complex hierarchies.
|
|
|
|
if( m_sheet->GetScreenCount() > 1 )
|
|
|
|
{
|
2021-11-23 18:55:01 +00:00
|
|
|
oldScreen = m_sheet->GetScreen();
|
2021-05-27 18:36:47 +00:00
|
|
|
m_sheet->SetScreen( nullptr );
|
2020-03-06 20:02:58 +00:00
|
|
|
loadFromFile = true;
|
|
|
|
}
|
|
|
|
}
|
2018-02-02 15:56:09 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SHEET_PATH& currentSheet = m_frame->GetCurrentSheet();
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
if( useScreen )
|
|
|
|
{
|
|
|
|
// Create a temporary sheet for recursion testing to prevent a possible recursion error.
|
2022-06-12 14:46:11 +00:00
|
|
|
std::unique_ptr< SCH_SHEET> tmpSheet = std::make_unique<SCH_SHEET>( &schematic );
|
2020-03-13 09:53:44 +00:00
|
|
|
tmpSheet->GetFields()[SHEETNAME] = m_fields->at( SHEETNAME );
|
2021-05-27 18:36:47 +00:00
|
|
|
tmpSheet->GetFields()[SHEETFILENAME].SetText( sheetFileName.GetFullPath() );
|
2020-03-06 20:02:58 +00:00
|
|
|
tmpSheet->SetScreen( useScreen );
|
|
|
|
|
|
|
|
// No need to check for valid library IDs if we are using an existing screen.
|
2020-05-13 02:00:37 +00:00
|
|
|
if( m_frame->CheckSheetForRecursion( tmpSheet.get(), ¤tSheet ) )
|
2020-03-06 20:02:58 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// It's safe to set the sheet screen now.
|
|
|
|
m_sheet->SetScreen( useScreen );
|
2024-04-18 19:47:34 +00:00
|
|
|
|
|
|
|
SCH_SHEET_LIST sheetHierarchy( m_sheet ); // The hierarchy of the loaded file.
|
|
|
|
|
2024-04-19 18:33:22 +00:00
|
|
|
sheetHierarchy.AddNewSymbolInstances( currentSheet, m_frame->Prj().GetProjectName() );
|
2024-04-18 19:47:34 +00:00
|
|
|
sheetHierarchy.AddNewSheetInstances( currentSheet,
|
|
|
|
fullHierarchy.GetLastVirtualPageNumber() );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
else if( loadFromFile )
|
|
|
|
{
|
2022-04-08 16:05:27 +00:00
|
|
|
bool restoreSheet = false;
|
|
|
|
|
2020-03-06 20:02:58 +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;
|
2020-05-13 02:00:37 +00:00
|
|
|
currentSheet.LastScreen()->Remove( m_sheet );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
if( !m_frame->LoadSheetFromFile( m_sheet, ¤tSheet, newAbsoluteFilename )
|
2021-05-27 18:36:47 +00:00
|
|
|
|| m_frame->CheckSheetForRecursion( m_sheet, ¤tSheet ) )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
if( restoreSheet )
|
2021-11-23 18:55:01 +00:00
|
|
|
{
|
|
|
|
// If we cleared the previous screen, restore it before returning to the user
|
|
|
|
if( oldScreen )
|
|
|
|
m_sheet->SetScreen( oldScreen );
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
currentSheet.LastScreen()->Append( m_sheet );
|
2021-11-23 18:55:01 +00:00
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( restoreSheet )
|
2020-05-13 02:00:37 +00:00
|
|
|
currentSheet.LastScreen()->Append( m_sheet );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_clearAnnotationNewItems )
|
|
|
|
*m_clearAnnotationNewItems = clearAnnotation;
|
|
|
|
|
2024-02-17 13:50:22 +00:00
|
|
|
// Rebuild the entire connection graph.
|
|
|
|
m_frame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
|
|
|
|
|
2018-02-02 15:56:09 +00:00
|
|
|
return true;
|
2012-10-13 18:54:33 +00:00
|
|
|
}
|
|
|
|
|
2014-08-24 22:49:31 +00:00
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
void DIALOG_SHEET_PROPERTIES::OnGridCellChanging( wxGridEvent& event )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2020-04-22 20:00:48 +00:00
|
|
|
bool success = true;
|
2020-03-06 20:02:58 +00:00
|
|
|
wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
|
2020-04-22 20:00:48 +00:00
|
|
|
wxControl* control = editor->GetControl();
|
|
|
|
wxTextEntry* textControl = dynamic_cast<wxTextEntry*>( control );
|
|
|
|
|
|
|
|
// Short-circuit the validator's more generic "can't be empty" message for the
|
|
|
|
// two mandatory fields:
|
|
|
|
if( event.GetRow() == SHEETNAME && event.GetCol() == FDC_VALUE )
|
|
|
|
{
|
|
|
|
if( textControl && textControl->IsEmpty() )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "A sheet must have a name." ) );
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
2020-04-26 20:53:29 +00:00
|
|
|
else if( event.GetRow() == SHEETFILENAME && event.GetCol() == FDC_VALUE && textControl )
|
2020-04-22 20:00:48 +00:00
|
|
|
{
|
2020-04-26 20:53:29 +00:00
|
|
|
if( textControl->IsEmpty() )
|
2020-04-22 20:00:48 +00:00
|
|
|
{
|
|
|
|
wxMessageBox( _( "A sheet must have a file specified." ) );
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( success && control && control->GetValidator() )
|
|
|
|
success = control->GetValidator()->Validate( control );
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2020-04-22 20:00:48 +00:00
|
|
|
if( !success )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
event.Veto();
|
|
|
|
m_delayedFocusRow = event.GetRow();
|
|
|
|
m_delayedFocusColumn = event.GetCol();
|
|
|
|
}
|
|
|
|
|
|
|
|
editor->DecRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
void DIALOG_SHEET_PROPERTIES::OnAddField( wxCommandEvent& event )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int fieldID = m_fields->size();
|
2023-02-19 03:40:07 +00:00
|
|
|
SCH_FIELD newField( VECTOR2I( 0, 0 ), fieldID, m_sheet,
|
2020-04-18 20:04:41 +00:00
|
|
|
SCH_SHEET::GetDefaultFieldName( fieldID ) );
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
newField.SetTextAngle( m_fields->at( SHEETNAME ).GetTextAngle() );
|
|
|
|
|
|
|
|
m_fields->push_back( newField );
|
|
|
|
|
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
|
|
|
|
|
|
|
m_grid->MakeCellVisible( m_fields->size() - 1, 0 );
|
|
|
|
m_grid->SetGridCursor( m_fields->size() - 1, 0 );
|
|
|
|
|
|
|
|
m_grid->EnableCellEditControl();
|
|
|
|
m_grid->ShowCellEditControl();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
void DIALOG_SHEET_PROPERTIES::OnDeleteField( wxCommandEvent& event )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
wxArrayInt selectedRows = m_grid->GetSelectedRows();
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
if( selectedRows.empty() && m_grid->GetGridCursorRow() >= 0 )
|
|
|
|
selectedRows.push_back( m_grid->GetGridCursorRow() );
|
|
|
|
|
|
|
|
if( selectedRows.empty() )
|
2020-03-06 20:02:58 +00:00
|
|
|
return;
|
2021-12-12 17:27:40 +00:00
|
|
|
|
|
|
|
for( int row : selectedRows )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
if( row < SHEET_MANDATORY_FIELDS )
|
|
|
|
{
|
|
|
|
DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
|
|
|
|
SHEET_MANDATORY_FIELDS ) );
|
|
|
|
return;
|
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_grid->CommitPendingChanges( true /* quiet mode */ );
|
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
// Reverse sort so deleting a row doesn't change the indexes of the other rows.
|
|
|
|
selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
for( int row : selectedRows )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
m_fields->erase( m_fields->begin() + row );
|
|
|
|
|
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
|
|
|
|
|
|
|
if( m_grid->GetNumberRows() > 0 )
|
|
|
|
{
|
|
|
|
m_grid->MakeCellVisible( std::max( 0, row-1 ), m_grid->GetGridCursorCol() );
|
|
|
|
m_grid->SetGridCursor( std::max( 0, row-1 ), m_grid->GetGridCursorCol() );
|
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
void DIALOG_SHEET_PROPERTIES::OnMoveUp( wxCommandEvent& event )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int i = m_grid->GetGridCursorRow();
|
|
|
|
|
|
|
|
if( i > SHEET_MANDATORY_FIELDS )
|
|
|
|
{
|
|
|
|
SCH_FIELD tmp = m_fields->at( (unsigned) i );
|
|
|
|
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
|
|
|
|
m_fields->insert( m_fields->begin() + i - 1, tmp );
|
|
|
|
m_grid->ForceRefresh();
|
|
|
|
|
|
|
|
m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
|
|
|
|
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
|
|
|
|
}
|
|
|
|
else
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
wxBell();
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
void DIALOG_SHEET_PROPERTIES::OnMoveDown( wxCommandEvent& event )
|
2019-08-25 23:45:10 +00:00
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
2019-08-25 23:45:10 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
int i = m_grid->GetGridCursorRow();
|
2019-08-25 23:45:10 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
if( i >= SHEET_MANDATORY_FIELDS && i < m_grid->GetNumberRows() - 1 )
|
2019-08-25 23:45:10 +00:00
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
SCH_FIELD tmp = m_fields->at( (unsigned) i );
|
|
|
|
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
|
|
|
|
m_fields->insert( m_fields->begin() + i + 1, tmp );
|
|
|
|
m_grid->ForceRefresh();
|
2019-08-25 23:45:10 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
|
|
|
|
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
|
2019-08-25 23:45:10 +00:00
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
else
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
wxBell();
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
2019-08-25 23:45:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-16 14:39:58 +00:00
|
|
|
void DIALOG_SHEET_PROPERTIES::AdjustGridColumns()
|
2012-10-13 18:54:33 +00:00
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
// Account for scroll bars
|
2021-12-16 14:39:58 +00:00
|
|
|
int width = KIPLATFORM::UI::GetUnobscuredSize( m_grid ).x;
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
m_grid->AutoSizeColumn( 0 );
|
2022-11-16 12:35:21 +00:00
|
|
|
m_grid->SetColSize( 0, std::max( 72, m_grid->GetColSize( 0 ) ) );
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
int fixedColsWidth = m_grid->GetColSize( 0 );
|
|
|
|
|
|
|
|
for( int i = 2; i < m_grid->GetNumberCols(); i++ )
|
|
|
|
fixedColsWidth += m_grid->GetColSize( i );
|
|
|
|
|
2022-11-16 12:35:21 +00:00
|
|
|
m_grid->SetColSize( 1, std::max( 120, width - fixedColsWidth ) );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
void DIALOG_SHEET_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2023-04-13 12:45:22 +00:00
|
|
|
std::bitset<64> shownColumns = m_grid->GetShownColumns();
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
if( shownColumns != m_shownColumns )
|
|
|
|
{
|
|
|
|
m_shownColumns = shownColumns;
|
|
|
|
|
|
|
|
if( !m_grid->IsCellEditControlShown() )
|
2021-12-16 14:39:58 +00:00
|
|
|
AdjustGridColumns();
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
|
|
|
|
2020-10-24 22:29:29 +00:00
|
|
|
// Propagate changes in sheetname to displayed hierarchical path
|
2022-04-30 12:37:40 +00:00
|
|
|
wxString path = m_frame->GetCurrentSheet().PathHumanReadable( false );
|
2020-10-24 22:29:29 +00:00
|
|
|
|
2022-04-30 12:37:40 +00:00
|
|
|
if( path.Last() != '/' )
|
|
|
|
path.Append( '/' );
|
2020-10-24 22:29:29 +00:00
|
|
|
|
|
|
|
wxGridCellEditor* editor = m_grid->GetCellEditor( SHEETNAME, FDC_VALUE );
|
|
|
|
wxControl* control = editor->GetControl();
|
|
|
|
wxTextEntry* textControl = dynamic_cast<wxTextEntry*>( control );
|
2020-11-18 17:54:41 +00:00
|
|
|
wxString sheetName;
|
2020-10-24 22:29:29 +00:00
|
|
|
|
|
|
|
if( textControl )
|
2020-11-18 17:54:41 +00:00
|
|
|
sheetName = textControl->GetValue();
|
2020-10-24 22:29:29 +00:00
|
|
|
else
|
2020-11-18 17:54:41 +00:00
|
|
|
sheetName = m_grid->GetCellValue( SHEETNAME, FDC_VALUE );
|
|
|
|
|
|
|
|
m_dummySheet.SetFields( *m_fields );
|
|
|
|
m_dummySheetNameField.SetText( sheetName );
|
2023-05-05 13:21:56 +00:00
|
|
|
path += m_dummySheetNameField.GetShownText( false );
|
2020-10-24 22:29:29 +00:00
|
|
|
|
|
|
|
editor->DecRef();
|
|
|
|
|
2022-04-30 12:37:40 +00:00
|
|
|
wxClientDC dc( m_hierarchicalPathLabel );
|
|
|
|
int width = m_sizerBottom->GetSize().x - m_stdDialogButtonSizer->GetSize().x
|
|
|
|
- m_hierarchicalPathLabel->GetSize().x
|
|
|
|
- 30;
|
|
|
|
|
|
|
|
path = wxControl::Ellipsize( path, dc, wxELLIPSIZE_START, width, wxELLIPSIZE_FLAGS_NONE );
|
|
|
|
|
|
|
|
if( m_hierarchicalPath->GetLabel() != path )
|
|
|
|
m_hierarchicalPath->SetLabel( path );
|
2020-10-24 22:29:29 +00:00
|
|
|
|
2020-03-06 20:02:58 +00:00
|
|
|
// Handle a delayed focus
|
|
|
|
if( m_delayedFocusRow >= 0 )
|
|
|
|
{
|
|
|
|
m_grid->SetFocus();
|
|
|
|
m_grid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
|
|
|
|
m_grid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn );
|
|
|
|
|
|
|
|
m_grid->EnableCellEditControl( true );
|
|
|
|
m_grid->ShowCellEditControl();
|
|
|
|
|
|
|
|
m_delayedFocusRow = -1;
|
|
|
|
m_delayedFocusColumn = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
void DIALOG_SHEET_PROPERTIES::OnSizeGrid( wxSizeEvent& event )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
2021-12-17 04:00:24 +00:00
|
|
|
auto new_size = event.GetSize();
|
2020-03-06 20:02:58 +00:00
|
|
|
|
2021-12-16 14:39:58 +00:00
|
|
|
if( m_size != new_size )
|
|
|
|
{
|
|
|
|
m_size = new_size;
|
|
|
|
|
|
|
|
AdjustGridColumns();
|
|
|
|
}
|
2020-03-06 20:02:58 +00:00
|
|
|
|
|
|
|
// Always propagate for a grid repaint (needed if the height changes, as well as width)
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-06 13:17:45 +00:00
|
|
|
void DIALOG_SHEET_PROPERTIES::OnInitDlg( wxInitDialogEvent& event )
|
2020-03-06 20:02:58 +00:00
|
|
|
{
|
|
|
|
TransferDataToWindow();
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2022-12-24 22:18:05 +00:00
|
|
|
|
|
|
|
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
|
|
|
|
|
|
|
if( cfg && cfg->m_Appearance.edit_sheet_width > 0 && cfg->m_Appearance.edit_sheet_height > 0 )
|
|
|
|
SetSize( cfg->m_Appearance.edit_sheet_width, cfg->m_Appearance.edit_sheet_height );
|
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
}
|