2020-03-10 18:46:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
#include <confirm.h>
|
2020-03-10 18:46:57 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2020-03-10 18:46:57 +00:00
|
|
|
#include <kiface_i.h>
|
|
|
|
#include <dialog_sch_import_settings.h>
|
2020-07-03 23:28:24 +00:00
|
|
|
#include <dialogs/panel_setup_netclasses.h>
|
2020-03-10 18:46:57 +00:00
|
|
|
#include <panel_setup_severities.h>
|
|
|
|
#include <panel_setup_formatting.h>
|
2020-03-11 21:43:02 +00:00
|
|
|
#include <panel_setup_pinmap.h>
|
2020-03-16 11:05:01 +00:00
|
|
|
#include <erc_item.h>
|
2020-03-26 11:02:59 +00:00
|
|
|
#include <panel_text_variables.h>
|
2020-06-08 02:19:46 +00:00
|
|
|
#include <project/project_file.h>
|
2020-07-03 23:28:24 +00:00
|
|
|
#include <project/net_settings.h>
|
2020-06-08 02:19:46 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2020-03-10 18:46:57 +00:00
|
|
|
#include "dialog_schematic_setup.h"
|
|
|
|
#include "panel_eeschema_template_fieldnames.h"
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) :
|
2020-07-15 23:08:16 +00:00
|
|
|
PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true,
|
2020-03-10 18:46:57 +00:00
|
|
|
_( "Import Settings from Another Project..." ) ),
|
|
|
|
m_frame( aFrame ),
|
|
|
|
m_severities( nullptr )
|
|
|
|
{
|
2020-07-06 10:51:04 +00:00
|
|
|
PROJECT_FILE& project = aFrame->Prj().GetProjectFile();
|
|
|
|
SCHEMATIC& schematic = aFrame->Schematic();
|
|
|
|
|
2020-04-12 16:17:57 +00:00
|
|
|
m_formatting = new PANEL_SETUP_FORMATTING( m_treebook, aFrame );
|
|
|
|
m_fieldNameTemplates = new PANEL_EESCHEMA_TEMPLATE_FIELDNAMES( aFrame, m_treebook, false );
|
|
|
|
m_pinMap = new PANEL_SETUP_PINMAP( m_treebook, aFrame );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_pinToPinError = ERC_ITEM::Create( ERCE_PIN_TO_PIN_WARNING );
|
|
|
|
m_severities = new PANEL_SETUP_SEVERITIES( this, ERC_ITEM::GetItemsWithSeverities(),
|
2020-07-06 10:51:04 +00:00
|
|
|
schematic.ErcSettings().m_Severities,
|
2020-07-04 08:57:05 +00:00
|
|
|
m_pinToPinError );
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2020-04-12 16:17:57 +00:00
|
|
|
m_textVars = new PANEL_TEXT_VARIABLES( m_treebook, &Prj() );
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
m_netclasses = new PANEL_SETUP_NETCLASSES( this, &project.NetSettings().m_NetClasses,
|
2020-07-08 18:29:16 +00:00
|
|
|
schematic.GetNetClassAssignmentCandidates(), true );
|
2020-07-03 23:28:24 +00:00
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
/*
|
2020-05-24 14:54:26 +00:00
|
|
|
* WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog().
|
2020-03-10 18:46:57 +00:00
|
|
|
*/
|
|
|
|
|
2020-07-20 13:45:46 +00:00
|
|
|
m_treebook->AddGroupEntry( _( "General" ) );
|
2020-03-10 18:46:57 +00:00
|
|
|
m_treebook->AddSubPage( m_formatting, _( "Formatting" ) );
|
|
|
|
m_treebook->AddSubPage( m_fieldNameTemplates, _( "Field Name Templates" ) );
|
|
|
|
|
2020-07-20 13:45:46 +00:00
|
|
|
m_treebook->AddGroupEntry( _( "Electrical Rules" ) );
|
2020-03-10 18:46:57 +00:00
|
|
|
m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
|
2020-04-28 08:55:44 +00:00
|
|
|
m_treebook->AddSubPage( m_pinMap, _( "Pin Conflicts Map" ) );
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2020-07-20 13:45:46 +00:00
|
|
|
m_treebook->AddGroupEntry( _( "Project" ) );
|
2020-07-03 23:28:24 +00:00
|
|
|
m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) );
|
2020-03-26 11:02:59 +00:00
|
|
|
m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) );
|
|
|
|
|
2020-04-10 15:01:11 +00:00
|
|
|
for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
|
|
|
|
m_macHack.push_back( true );
|
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
// Connect Events
|
|
|
|
m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
|
|
|
|
wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this );
|
|
|
|
|
|
|
|
FinishDialogSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_SCHEMATIC_SETUP::~DIALOG_SCHEMATIC_SETUP()
|
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
delete m_pinToPinError;
|
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
|
|
|
|
wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SCHEMATIC_SETUP::OnPageChange( wxBookCtrlEvent& event )
|
|
|
|
{
|
2020-03-26 11:02:59 +00:00
|
|
|
int page = event.GetSelection();
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2020-07-15 23:08:16 +00:00
|
|
|
// Enable the reset button only if the page is resettable
|
|
|
|
if( m_resetButton )
|
|
|
|
{
|
|
|
|
if( auto panel = dynamic_cast<RESETTABLE_PANEL*>( m_treebook->GetPage( page ) ) )
|
|
|
|
{
|
|
|
|
m_resetButton->SetToolTip( panel->GetResetTooltip() );
|
|
|
|
m_resetButton->Enable( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_resetButton->SetToolTip( wxString() );
|
|
|
|
m_resetButton->Enable( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Work around an OSX bug where the wxGrid children don't get placed correctly until
|
|
|
|
// the first resize event
|
|
|
|
#ifdef __WXMAC__
|
2020-03-26 11:02:59 +00:00
|
|
|
if( m_macHack[ page ] )
|
|
|
|
{
|
|
|
|
wxSize pageSize = m_treebook->GetPage( page )->GetSize();
|
|
|
|
pageSize.x -= 1;
|
2020-07-03 23:28:24 +00:00
|
|
|
pageSize.y += 2;
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
m_treebook->GetPage( page )->SetSize( pageSize );
|
|
|
|
m_macHack[ page ] = false;
|
2020-03-10 18:46:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-07-15 23:08:16 +00:00
|
|
|
|
|
|
|
Layout();
|
2020-03-10 18:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Run Import Settings... action
|
|
|
|
void DIALOG_SCHEMATIC_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
|
|
|
|
|
|
|
|
if( importDlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
wxFileName projectFn( importDlg.GetFilePath() );
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
|
2020-03-13 09:53:44 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
wxString msg = wxString::Format( _( "Error importing settings from project:\n"
|
|
|
|
"Project file %s could not be loaded" ),
|
|
|
|
projectFn.GetFullPath() );
|
|
|
|
DisplayErrorMessage( this, msg );
|
2020-03-13 09:53:44 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
return;
|
2020-03-13 09:53:44 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
|
2020-03-13 09:53:44 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
SCHEMATIC otherSch( otherPrj );
|
|
|
|
|
|
|
|
TEMPLATES templateMgr;
|
|
|
|
PROJECT_FILE& file = otherPrj->GetProjectFile();
|
|
|
|
|
|
|
|
wxASSERT( file.m_SchematicSettings );
|
|
|
|
|
|
|
|
file.m_SchematicSettings->m_TemplateFieldNames = &templateMgr;
|
|
|
|
file.m_SchematicSettings->LoadFromFile();
|
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
if( importDlg.m_FormattingOpt->GetValue() )
|
2020-06-08 02:19:46 +00:00
|
|
|
m_formatting->ImportSettingsFrom( *file.m_SchematicSettings );
|
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
|
2020-06-08 02:19:46 +00:00
|
|
|
m_fieldNameTemplates->ImportSettingsFrom( file.m_SchematicSettings->m_TemplateFieldNames );
|
2020-03-13 09:53:44 +00:00
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
if( importDlg.m_PinMapOpt->GetValue() )
|
2020-07-04 08:57:05 +00:00
|
|
|
m_pinMap->ImportSettingsFrom( file.m_ErcSettings->m_PinMap );
|
2020-03-13 09:53:44 +00:00
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
if( importDlg.m_SeveritiesOpt->GetValue() )
|
2020-06-08 02:19:46 +00:00
|
|
|
m_severities->ImportSettingsFrom( file.m_ErcSettings->m_Severities );
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
if( importDlg.m_NetClassesOpt->GetValue() )
|
|
|
|
m_netclasses->ImportSettingsFrom( &file.m_NetSettings->m_NetClasses );
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
|
2020-03-10 18:46:57 +00:00
|
|
|
}
|