2020-03-10 18:46:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-05-11 00:24:06 +00:00
|
|
|
* Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-03-10 18:46:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 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>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-03-10 18:46:57 +00:00
|
|
|
#include <dialog_sch_import_settings.h>
|
2020-07-03 23:28:24 +00:00
|
|
|
#include <dialogs/panel_setup_netclasses.h>
|
2020-12-17 13:12:18 +00:00
|
|
|
#include <dialogs/panel_setup_severities.h>
|
2022-08-21 11:26:47 +00:00
|
|
|
#include <dialogs/panel_setup_buses.h>
|
2020-03-10 18:46:57 +00:00
|
|
|
#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"
|
2021-08-29 23:33:08 +00:00
|
|
|
#include "panel_template_fieldnames.h"
|
2020-03-10 18:46:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
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..." ) ),
|
2023-05-11 00:24:06 +00:00
|
|
|
m_frame( aFrame )
|
2020-03-10 18:46:57 +00:00
|
|
|
{
|
2022-12-15 19:35:35 +00:00
|
|
|
SetEvtHandlerEnabled( false );
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_pinToPinError = ERC_ITEM::Create( ERCE_PIN_TO_PIN_WARNING );
|
2022-08-21 11:26:47 +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
|
|
|
*/
|
|
|
|
|
2021-12-28 00:08:41 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "General" ) );
|
2023-05-11 00:24:06 +00:00
|
|
|
|
|
|
|
m_formattingPage = m_treebook->GetPageCount();
|
|
|
|
m_treebook->AddLazySubPage(
|
|
|
|
[this]( wxWindow* aParent ) -> wxWindow*
|
|
|
|
{
|
|
|
|
return new PANEL_SETUP_FORMATTING( aParent, m_frame );
|
|
|
|
}, _( "Formatting" ) );
|
|
|
|
|
|
|
|
m_fieldNameTemplatesPage = m_treebook->GetPageCount();
|
|
|
|
m_treebook->AddLazySubPage(
|
|
|
|
[this]( wxWindow* aParent ) -> wxWindow*
|
|
|
|
{
|
|
|
|
SCHEMATIC_SETTINGS& settings = m_frame->Schematic().Settings();
|
|
|
|
return new PANEL_TEMPLATE_FIELDNAMES( aParent, &settings.m_TemplateFieldNames );
|
|
|
|
}, _( "Field Name Templates" ) );
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2021-12-28 00:08:41 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Electrical Rules" ) );
|
2023-05-14 08:11:38 +00:00
|
|
|
|
|
|
|
m_severitiesPage = m_treebook->GetPageCount();
|
2023-05-11 00:24:06 +00:00
|
|
|
m_treebook->AddLazySubPage(
|
|
|
|
[this]( wxWindow* aParent ) -> wxWindow*
|
|
|
|
{
|
|
|
|
ERC_SETTINGS& ercSettings = m_frame->Schematic().ErcSettings();
|
|
|
|
return new PANEL_SETUP_SEVERITIES( aParent, ERC_ITEM::GetItemsWithSeverities(),
|
|
|
|
ercSettings.m_ERCSeverities,
|
|
|
|
m_pinToPinError.get() );
|
|
|
|
}, _( "Violation Severity" ) );
|
|
|
|
|
|
|
|
m_pinMapPage = m_treebook->GetPageCount();
|
|
|
|
m_treebook->AddLazySubPage(
|
|
|
|
[this]( wxWindow* aParent ) -> wxWindow*
|
|
|
|
{
|
|
|
|
return new PANEL_SETUP_PINMAP( aParent, m_frame );
|
|
|
|
}, _( "Pin Conflicts Map" ) );
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2021-12-28 00:08:41 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Project" ) );
|
2023-05-11 00:24:06 +00:00
|
|
|
|
|
|
|
m_netclassesPage = m_treebook->GetPageCount();
|
|
|
|
m_treebook->AddLazySubPage(
|
|
|
|
[this]( wxWindow* aParent ) -> wxWindow*
|
|
|
|
{
|
|
|
|
SCHEMATIC& schematic = m_frame->Schematic();
|
|
|
|
return new PANEL_SETUP_NETCLASSES( aParent, m_frame,
|
|
|
|
m_frame->Prj().GetProjectFile().NetSettings(),
|
|
|
|
schematic.GetNetClassAssignmentCandidates(),
|
|
|
|
true );
|
|
|
|
}, _( "Net Classes" ) );
|
|
|
|
|
|
|
|
m_busesPage = m_treebook->GetPageCount();
|
|
|
|
m_treebook->AddLazySubPage(
|
|
|
|
[this]( wxWindow* aParent ) -> wxWindow*
|
|
|
|
{
|
|
|
|
return new PANEL_SETUP_BUSES( aParent, m_frame );
|
|
|
|
}, _( "Bus Alias Definitions" ) );
|
|
|
|
|
|
|
|
m_treebook->AddLazySubPage(
|
|
|
|
[this]( wxWindow* aParent ) -> wxWindow*
|
|
|
|
{
|
|
|
|
return new PANEL_TEXT_VARIABLES( aParent, &Prj() );
|
|
|
|
}, _( "Text Variables" ) );
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2020-04-10 15:01:11 +00:00
|
|
|
for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
|
2021-08-29 23:33:08 +00:00
|
|
|
m_treebook->ExpandNode( i );
|
2020-04-10 15:01:11 +00:00
|
|
|
|
2023-05-11 00:24:06 +00:00
|
|
|
// This is unfortunate, but it's the cost of lazy-loading the panels
|
|
|
|
m_treebook->SetMinSize( wxSize( 920, 460 ) );
|
|
|
|
m_treebook->SetInitialSize( wxSize( 920, 460 ) );
|
|
|
|
|
2022-12-15 19:35:35 +00:00
|
|
|
SetEvtHandlerEnabled( true );
|
|
|
|
|
2022-01-04 12:09:02 +00:00
|
|
|
finishDialogSettings();
|
2021-10-04 15:46:32 +00:00
|
|
|
|
2020-08-30 20:04:39 +00:00
|
|
|
if( Prj().IsReadOnly() )
|
2021-07-10 08:47:49 +00:00
|
|
|
{
|
2021-10-05 20:30:15 +00:00
|
|
|
m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be "
|
|
|
|
"editable." ), wxICON_WARNING );
|
2021-10-04 15:46:32 +00:00
|
|
|
}
|
2021-12-28 14:43:57 +00:00
|
|
|
|
|
|
|
wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
|
|
|
|
|
|
|
|
wxQueueEvent( m_treebook, evt.Clone() );
|
2020-03-10 18:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_SCHEMATIC_SETUP::~DIALOG_SCHEMATIC_SETUP()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-10 08:12:22 +00:00
|
|
|
void DIALOG_SCHEMATIC_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
|
2020-03-10 18:46:57 +00:00
|
|
|
{
|
2022-09-10 08:12:22 +00:00
|
|
|
PAGED_DIALOG::onPageChanged( aEvent );
|
2021-12-28 14:43:57 +00:00
|
|
|
|
2022-09-10 08:12:22 +00:00
|
|
|
int page = aEvent.GetSelection();
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2021-10-06 23:16:20 +00:00
|
|
|
if( Prj().IsReadOnly() )
|
|
|
|
KIUI::Disable( m_treebook->GetPage( page ) );
|
2020-03-10 18:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-10 08:12:22 +00:00
|
|
|
void DIALOG_SCHEMATIC_SETUP::onAuxiliaryAction( wxCommandEvent& event )
|
2020-03-10 18:46:57 +00:00
|
|
|
{
|
|
|
|
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"
|
2021-06-27 13:24:02 +00:00
|
|
|
"Project file %s could not be loaded." ),
|
2020-06-08 02:19:46 +00:00
|
|
|
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-08-30 17:57:10 +00:00
|
|
|
PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
|
|
|
|
SCHEMATIC otherSch( otherPrj );
|
2020-06-08 02:19:46 +00:00
|
|
|
PROJECT_FILE& file = otherPrj->GetProjectFile();
|
|
|
|
|
|
|
|
wxASSERT( file.m_SchematicSettings );
|
|
|
|
|
|
|
|
file.m_SchematicSettings->LoadFromFile();
|
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
if( importDlg.m_FormattingOpt->GetValue() )
|
2023-05-11 00:24:06 +00:00
|
|
|
{
|
|
|
|
static_cast<PANEL_SETUP_FORMATTING*>( m_treebook->ResolvePage( m_formattingPage ) )
|
|
|
|
->ImportSettingsFrom( *file.m_SchematicSettings );
|
|
|
|
}
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
|
2023-05-11 00:24:06 +00:00
|
|
|
{
|
|
|
|
static_cast<PANEL_TEMPLATE_FIELDNAMES*>( m_treebook->ResolvePage( m_fieldNameTemplatesPage ) )
|
|
|
|
->ImportSettingsFrom( &otherSch.Settings().m_TemplateFieldNames );
|
|
|
|
}
|
2020-03-13 09:53:44 +00:00
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
if( importDlg.m_PinMapOpt->GetValue() )
|
2023-05-11 00:24:06 +00:00
|
|
|
{
|
|
|
|
static_cast<PANEL_SETUP_PINMAP*>( m_treebook->ResolvePage( m_pinMapPage ) )
|
|
|
|
->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() )
|
2023-05-11 00:24:06 +00:00
|
|
|
{
|
|
|
|
static_cast<PANEL_SETUP_SEVERITIES*>( m_treebook->ResolvePage( m_severitiesPage ) )
|
|
|
|
->ImportSettingsFrom( file.m_ErcSettings->m_ERCSeverities );
|
|
|
|
}
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
if( importDlg.m_NetClassesOpt->GetValue() )
|
2023-05-11 00:24:06 +00:00
|
|
|
{
|
|
|
|
static_cast<PANEL_SETUP_NETCLASSES*>( m_treebook->ResolvePage( m_netclassesPage ) )
|
|
|
|
->ImportSettingsFrom( file.m_NetSettings );
|
|
|
|
}
|
2020-07-06 10:51:04 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
|
2020-03-10 18:46:57 +00:00
|
|
|
}
|