2018-04-28 15:22:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-08-14 11:03:18 +00:00
|
|
|
* Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-04-28 15:22:25 +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/>.
|
|
|
|
*/
|
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <panel_setup_layers.h>
|
|
|
|
#include <panel_setup_text_and_graphics.h>
|
2021-01-26 11:41:47 +00:00
|
|
|
#include <panel_setup_constraints.h>
|
2020-12-17 16:43:46 +00:00
|
|
|
#include <dialogs/panel_setup_netclasses.h>
|
2018-07-17 06:52:33 +00:00
|
|
|
#include <panel_setup_tracks_and_vias.h>
|
2018-04-28 15:22:25 +00:00
|
|
|
#include <panel_setup_mask_and_paste.h>
|
2019-07-27 19:09:43 +00:00
|
|
|
#include <../board_stackup_manager/panel_board_stackup.h>
|
2021-02-24 21:20:11 +00:00
|
|
|
#include <../board_stackup_manager/panel_board_finish.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <confirm.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-03-16 11:05:01 +00:00
|
|
|
#include <drc/drc_item.h>
|
2020-03-10 18:46:57 +00:00
|
|
|
#include <dialog_import_settings.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <io_mgr.h>
|
2020-12-17 13:12:18 +00:00
|
|
|
#include <dialogs/panel_setup_severities.h>
|
2020-03-26 11:02:59 +00:00
|
|
|
#include <panel_text_variables.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <project.h>
|
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2021-02-12 03:19:46 +00:00
|
|
|
#include <widgets/resettable_panel.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <widgets/wx_progress_reporters.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
#include "dialog_board_setup.h"
|
2020-05-16 22:30:30 +00:00
|
|
|
#include "panel_setup_rules.h"
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2021-06-03 15:41:26 +00:00
|
|
|
#include <wx/treebook.h>
|
|
|
|
|
2021-02-12 03:19:46 +00:00
|
|
|
using std::placeholders::_1;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
|
2020-12-17 13:12:18 +00:00
|
|
|
PAGED_DIALOG( aFrame, _( "Board Setup" ), false,
|
|
|
|
_( "Import Settings from Another Board..." ) ),
|
2018-04-28 15:22:25 +00:00
|
|
|
m_frame( aFrame )
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
PROJECT_FILE& project = aFrame->Prj().GetProjectFile();
|
2020-07-06 10:51:04 +00:00
|
|
|
BOARD* board = aFrame->GetBoard();
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
|
2020-07-03 22:30:23 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
m_layers = new PANEL_SETUP_LAYERS( this, aFrame );
|
|
|
|
m_textAndGraphics = new PANEL_SETUP_TEXT_AND_GRAPHICS( this, aFrame );
|
2021-08-25 23:14:36 +00:00
|
|
|
m_formatting = new PANEL_SETUP_FORMATTING( this, aFrame );
|
2021-01-26 11:41:47 +00:00
|
|
|
m_constraints = new PANEL_SETUP_CONSTRAINTS( this, aFrame );
|
2020-05-16 22:30:30 +00:00
|
|
|
m_rules = new PANEL_SETUP_RULES( this, aFrame );
|
2022-08-18 16:56:36 +00:00
|
|
|
m_tracksAndVias = new PANEL_SETUP_TRACKS_AND_VIAS( this, aFrame );
|
2018-04-28 15:22:25 +00:00
|
|
|
m_maskAndPaste = new PANEL_SETUP_MASK_AND_PASTE( this, aFrame );
|
2019-07-27 19:09:43 +00:00
|
|
|
m_physicalStackup = new PANEL_SETUP_BOARD_STACKUP( this, aFrame, m_layers );
|
2022-12-05 17:39:18 +00:00
|
|
|
m_boardFinish = new PANEL_SETUP_BOARD_FINISH( this, aFrame );
|
2020-07-06 10:51:04 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_severities = new PANEL_SETUP_SEVERITIES( this, DRC_ITEM::GetItemsWithSeverities(),
|
|
|
|
bds.m_DRCSeverities );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netclasses = new PANEL_SETUP_NETCLASSES( this, aFrame, project.NetSettings(),
|
2020-07-08 18:29:16 +00:00
|
|
|
board->GetNetClassAssignmentCandidates(), false );
|
2020-07-06 10:51:04 +00:00
|
|
|
|
2020-05-27 07:24:32 +00:00
|
|
|
m_textVars = new PANEL_TEXT_VARIABLES( m_treebook, &Prj() );
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2018-11-17 00:33:20 +00:00
|
|
|
/*
|
2020-05-24 14:54:26 +00:00
|
|
|
* WARNING: If you change page names you MUST update calls to ShowBoardSetupDialog().
|
2018-11-17 00:33:20 +00:00
|
|
|
*/
|
|
|
|
|
2021-12-28 00:05:51 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Board Stackup" ) );
|
2021-02-24 02:31:12 +00:00
|
|
|
|
2021-12-15 10:01:46 +00:00
|
|
|
m_currentPage = -1;
|
|
|
|
|
2021-02-24 02:31:12 +00:00
|
|
|
/*
|
|
|
|
* WARNING: Code currently relies on the layers setup coming before the physical stackup panel,
|
|
|
|
* and thus transferring data to the board first. See comment in
|
|
|
|
* PANEL_SETUP_BOARD_STACKUP::TransferDataFromWindow and rework this logic if it is determined
|
|
|
|
* that the order of these pages should be changed.
|
|
|
|
*/
|
2019-07-27 19:09:43 +00:00
|
|
|
m_treebook->AddSubPage( m_layers, _( "Board Editor Layers" ) );
|
2021-02-24 02:31:12 +00:00
|
|
|
m_layerSetupPage = 1;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-08-14 20:18:11 +00:00
|
|
|
m_treebook->AddSubPage( m_physicalStackup, _( "Physical Stackup" ) );
|
2021-12-28 14:43:57 +00:00
|
|
|
|
2019-07-27 19:09:43 +00:00
|
|
|
// Change this value if m_physicalStackup is not the page 2 of m_treebook
|
|
|
|
m_physicalStackupPage = 2; // The page number (from 0) to select the m_physicalStackup panel
|
2021-08-14 20:18:11 +00:00
|
|
|
|
2021-02-24 21:20:11 +00:00
|
|
|
m_treebook->AddSubPage( m_boardFinish, _( "Board Finish" ) );
|
2018-07-15 23:15:48 +00:00
|
|
|
m_treebook->AddSubPage( m_maskAndPaste, _( "Solder Mask/Paste" ) );
|
2019-08-19 16:46:25 +00:00
|
|
|
|
2021-12-28 00:05:51 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Text & Graphics" ) );
|
2021-01-10 17:00:13 +00:00
|
|
|
m_treebook->AddSubPage( m_textAndGraphics, _( "Defaults" ) );
|
2022-07-20 19:34:31 +00:00
|
|
|
m_treebook->AddSubPage( m_formatting, _( "Formatting" ) );
|
2021-01-10 17:00:13 +00:00
|
|
|
m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) );
|
|
|
|
|
2021-12-28 00:05:51 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Design Rules" ) );
|
2019-08-19 16:46:25 +00:00
|
|
|
m_treebook->AddSubPage( m_constraints, _( "Constraints" ) );
|
2021-01-10 17:00:13 +00:00
|
|
|
m_treebook->AddSubPage( m_tracksAndVias, _( "Pre-defined Sizes" ) );
|
2020-07-03 23:28:24 +00:00
|
|
|
m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) );
|
2021-01-10 17:00:13 +00:00
|
|
|
m_treebook->AddSubPage( m_rules, _( "Custom Rules" ) );
|
|
|
|
m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
|
2020-03-26 11:02:59 +00:00
|
|
|
|
2022-01-03 22:49:04 +00:00
|
|
|
for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
|
|
|
|
m_treebook->ExpandNode( i );
|
|
|
|
|
2022-10-01 22:53:15 +00:00
|
|
|
m_treebook->SetMinSize( wxSize( -1, 580 ) );
|
2021-06-26 09:31:25 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2021-10-04 15:46:32 +00:00
|
|
|
|
|
|
|
if( Prj().IsReadOnly() )
|
|
|
|
{
|
2021-10-05 20:30:15 +00:00
|
|
|
m_infoBar->ShowMessage( _( "Project is missing or read-only. Some 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() );
|
2019-07-27 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_BOARD_SETUP::~DIALOG_BOARD_SETUP()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-10 08:12:22 +00:00
|
|
|
void DIALOG_BOARD_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
|
2019-07-27 19:09:43 +00:00
|
|
|
{
|
2022-09-10 08:12:22 +00:00
|
|
|
PAGED_DIALOG::onPageChanged( aEvent );
|
2021-12-28 14:43:57 +00:00
|
|
|
|
|
|
|
int page = aEvent.GetSelection();
|
2021-10-05 20:30:15 +00:00
|
|
|
|
2021-12-15 10:01:46 +00:00
|
|
|
// Ensure layer page always gets updated even if we aren't moving towards it
|
|
|
|
if( m_currentPage == m_physicalStackupPage )
|
|
|
|
m_layers->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
|
|
|
|
|
2021-10-05 20:30:15 +00:00
|
|
|
if( page == m_physicalStackupPage )
|
2019-07-27 19:09:43 +00:00
|
|
|
m_physicalStackup->OnLayersOptionsChanged( m_layers->GetUILayerMask() );
|
2021-10-06 23:16:20 +00:00
|
|
|
else if( Prj().IsReadOnly() )
|
2021-10-05 20:30:15 +00:00
|
|
|
KIUI::Disable( m_treebook->GetPage( page ) );
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2021-12-15 10:01:46 +00:00
|
|
|
m_currentPage = page;
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-10 08:12:22 +00:00
|
|
|
void DIALOG_BOARD_SETUP::onAuxiliaryAction( wxCommandEvent& aEvent )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
|
|
|
DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
|
|
|
|
|
|
|
|
if( importDlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
wxFileName boardFn( importDlg.GetFilePath() );
|
|
|
|
wxFileName projectFn( boardFn );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
projectFn.SetExt( ProjectFileExtension );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
|
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
wxString msg = wxString::Format( _( "Error importing settings from board:\n"
|
2020-05-31 21:42:04 +00:00
|
|
|
"Associated project file %s could not be loaded" ),
|
|
|
|
projectFn.GetFullPath() );
|
|
|
|
DisplayErrorMessage( this, msg );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-07 17:08:45 +00:00
|
|
|
// Flag so user can stop work if it will result in deleted inner copper layers
|
|
|
|
// and still clean up this function properly.
|
|
|
|
bool okToProceed = true;
|
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::KICAD_SEXP ) );
|
|
|
|
|
2021-02-02 00:23:07 +00:00
|
|
|
BOARD* otherBoard = nullptr;
|
2020-05-31 21:42:04 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-06-23 22:53:08 +00:00
|
|
|
WX_PROGRESS_REPORTER progressReporter( this, _( "Loading PCB" ), 1 );
|
|
|
|
|
|
|
|
otherBoard = pi->Load( boardFn.GetFullPath(), nullptr, nullptr, nullptr,
|
|
|
|
&progressReporter );
|
2020-08-07 17:08:45 +00:00
|
|
|
|
|
|
|
if( importDlg.m_LayersOpt->GetValue() )
|
|
|
|
{
|
|
|
|
BOARD* loadedBoard = m_frame->GetBoard();
|
|
|
|
|
2020-09-20 12:42:43 +00:00
|
|
|
// Check if "Import Settings" board has more layers than the current board.
|
|
|
|
okToProceed = m_layers->CheckCopperLayerCount( loadedBoard, otherBoard );
|
2020-08-07 17:08:45 +00:00
|
|
|
}
|
2020-05-31 21:42:04 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2020-09-20 12:42:43 +00:00
|
|
|
// You wouldn't think boardFn.GetFullPath() would throw, but we get a stack buffer
|
|
|
|
// underflow from ASAN. While it's probably an ASAN error, a second try/catch doesn't
|
|
|
|
// cost us much.
|
|
|
|
try
|
2020-05-31 21:42:04 +00:00
|
|
|
{
|
2020-09-20 12:42:43 +00:00
|
|
|
if( ioe.Problem() != wxT( "CANCEL" ) )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _( "Error loading board file:\n%s" ),
|
|
|
|
boardFn.GetFullPath() );
|
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( otherPrj != &m_frame->Prj() )
|
|
|
|
m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
// That was already our best-efforts
|
2020-05-31 21:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-07 17:08:45 +00:00
|
|
|
if( okToProceed )
|
|
|
|
{
|
|
|
|
otherBoard->SetProject( otherPrj );
|
|
|
|
|
2021-10-11 18:46:02 +00:00
|
|
|
// If layers options are imported, import also the stackup
|
|
|
|
// layers options and stackup are linked, so they cannot be imported
|
|
|
|
// separately, and stackup can be imported only after layers options
|
2020-08-07 17:08:45 +00:00
|
|
|
if( importDlg.m_LayersOpt->GetValue() )
|
2021-10-11 18:46:02 +00:00
|
|
|
{
|
|
|
|
m_physicalStackup->ImportSettingsFrom( otherBoard );
|
2022-10-16 17:28:58 +00:00
|
|
|
m_layers->ImportSettingsFrom( otherBoard );
|
2021-08-25 23:14:36 +00:00
|
|
|
m_boardFinish->ImportSettingsFrom( otherBoard );
|
2021-10-11 18:46:02 +00:00
|
|
|
}
|
2020-08-07 17:08:45 +00:00
|
|
|
|
|
|
|
if( importDlg.m_TextAndGraphicsOpt->GetValue() )
|
|
|
|
m_textAndGraphics->ImportSettingsFrom( otherBoard );
|
|
|
|
|
2021-08-25 23:14:36 +00:00
|
|
|
if( importDlg.m_FormattingOpt->GetValue() )
|
|
|
|
m_formatting->ImportSettingsFrom( otherBoard );
|
|
|
|
|
2020-08-07 17:08:45 +00:00
|
|
|
if( importDlg.m_ConstraintsOpt->GetValue() )
|
|
|
|
m_constraints->ImportSettingsFrom( otherBoard );
|
|
|
|
|
|
|
|
if( importDlg.m_NetclassesOpt->GetValue() )
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netclasses->ImportSettingsFrom( otherPrj->GetProjectFile().m_NetSettings );
|
2020-08-07 17:08:45 +00:00
|
|
|
|
|
|
|
if( importDlg.m_TracksAndViasOpt->GetValue() )
|
|
|
|
m_tracksAndVias->ImportSettingsFrom( otherBoard );
|
|
|
|
|
|
|
|
if( importDlg.m_MaskAndPasteOpt->GetValue() )
|
|
|
|
m_maskAndPaste->ImportSettingsFrom( otherBoard );
|
|
|
|
|
|
|
|
if( importDlg.m_SeveritiesOpt->GetValue() )
|
|
|
|
m_severities->ImportSettingsFrom( otherBoard->GetDesignSettings().m_DRCSeverities );
|
|
|
|
|
2020-09-17 19:53:56 +00:00
|
|
|
if( otherPrj != &m_frame->Prj() )
|
|
|
|
otherBoard->ClearProject();
|
2020-08-07 17:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up and free memory before leaving
|
2020-09-17 19:53:56 +00:00
|
|
|
if( otherPrj != &m_frame->Prj() )
|
|
|
|
m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
|
2020-03-10 18:46:57 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
delete otherBoard;
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|