2020-03-10 18:46:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-06-03 15:41:26 +00:00
|
|
|
* Copyright (C) 2020-2021 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>
|
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"
|
2021-06-03 15:41:26 +00:00
|
|
|
#include <wx/treebook.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..." ) ),
|
|
|
|
m_frame( aFrame ),
|
|
|
|
m_severities( nullptr )
|
|
|
|
{
|
2021-08-29 23:33:08 +00:00
|
|
|
PROJECT_FILE& project = aFrame->Prj().GetProjectFile();
|
|
|
|
SCHEMATIC& schematic = aFrame->Schematic();
|
|
|
|
SCHEMATIC_SETTINGS& settings = schematic.Settings();
|
2020-07-06 10:51:04 +00:00
|
|
|
|
2020-04-12 16:17:57 +00:00
|
|
|
m_formatting = new PANEL_SETUP_FORMATTING( m_treebook, aFrame );
|
2021-08-29 23:33:08 +00:00
|
|
|
|
|
|
|
m_fieldNameTemplates = new PANEL_TEMPLATE_FIELDNAMES( m_treebook,
|
|
|
|
&settings.m_TemplateFieldNames );
|
|
|
|
|
2020-04-12 16:17:57 +00:00
|
|
|
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-08-11 13:33:16 +00:00
|
|
|
m_pinToPinError.get() );
|
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
|
|
|
|
2021-12-22 21:43:41 +00:00
|
|
|
m_netclasses = new PANEL_SETUP_NETCLASSES( this, aFrame, &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
|
|
|
*/
|
|
|
|
|
2021-12-28 00:08:41 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "General" ) );
|
2020-03-10 18:46:57 +00:00
|
|
|
m_treebook->AddSubPage( m_formatting, _( "Formatting" ) );
|
|
|
|
m_treebook->AddSubPage( m_fieldNameTemplates, _( "Field Name Templates" ) );
|
|
|
|
|
2021-12-28 00:08:41 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "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
|
|
|
|
2021-12-28 00:08:41 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "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 )
|
2021-08-29 23:33:08 +00:00
|
|
|
m_treebook->ExpandNode( i );
|
2020-04-10 15:01:11 +00:00
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-28 14:43:57 +00:00
|
|
|
void DIALOG_SCHEMATIC_SETUP::OnPageChanged( wxBookCtrlEvent& event )
|
2020-03-10 18:46:57 +00:00
|
|
|
{
|
2021-12-28 14:43:57 +00:00
|
|
|
PAGED_DIALOG::OnPageChanged( event );
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
int page = event.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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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"
|
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() )
|
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-08-30 17:57:10 +00:00
|
|
|
m_fieldNameTemplates->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() )
|
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
|
|
|
}
|