2018-04-28 15:22:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-07-27 19:09:43 +00:00
|
|
|
* Copyright (C) 2017-2019 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>
|
|
|
|
#include <panel_setup_feature_constraints.h>
|
|
|
|
#include <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>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <confirm.h>
|
2018-04-28 15:22:25 +00:00
|
|
|
#include <kiface_i.h>
|
2020-03-10 18:46:57 +00:00
|
|
|
#include <drc/drc.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-03-10 18:46:57 +00:00
|
|
|
#include <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>
|
|
|
|
#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
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
|
2020-05-31 21:42:04 +00:00
|
|
|
PAGED_DIALOG( aFrame, _( "Board Setup" ), _( "Import Settings from Another Board..." ) ),
|
2018-04-28 15:22:25 +00:00
|
|
|
m_frame( aFrame )
|
|
|
|
{
|
|
|
|
m_layers = new PANEL_SETUP_LAYERS( this, aFrame );
|
|
|
|
m_textAndGraphics = new PANEL_SETUP_TEXT_AND_GRAPHICS( this, aFrame );
|
|
|
|
m_constraints = new PANEL_SETUP_FEATURE_CONSTRAINTS( this, aFrame );
|
|
|
|
m_netclasses = new PANEL_SETUP_NETCLASSES( this, aFrame, m_constraints );
|
2020-05-16 22:30:30 +00:00
|
|
|
m_rules = new PANEL_SETUP_RULES( this, aFrame );
|
2018-07-17 06:52:33 +00:00
|
|
|
m_tracksAndVias = new PANEL_SETUP_TRACKS_AND_VIAS( this, aFrame, m_constraints );
|
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 );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = aFrame->GetDesignSettings();
|
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
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2019-07-27 19:09:43 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( this ), _( "Board Stackup" ) );
|
|
|
|
m_treebook->AddSubPage( m_layers, _( "Board Editor Layers" ) );
|
|
|
|
m_treebook->AddSubPage( m_physicalStackup, _( "Physical Stackup" ) );
|
|
|
|
// 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
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2019-08-19 16:46:25 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( this ), _( "Defaults" ) );
|
|
|
|
m_treebook->AddSubPage( m_textAndGraphics, _( "Text & Graphics" ) );
|
2018-07-17 06:52:33 +00:00
|
|
|
m_treebook->AddSubPage( m_tracksAndVias, _( "Tracks & Vias" ) );
|
2018-07-15 23:15:48 +00:00
|
|
|
m_treebook->AddSubPage( m_maskAndPaste, _( "Solder Mask/Paste" ) );
|
2019-08-19 16:46:25 +00:00
|
|
|
|
|
|
|
m_treebook->AddPage( new wxPanel( this ), _( "Design Rules" ) );
|
|
|
|
m_treebook->AddSubPage( m_constraints, _( "Constraints" ) );
|
|
|
|
m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) );
|
2020-05-16 22:30:30 +00:00
|
|
|
m_treebook->AddSubPage( m_rules, _( "Rules" ) );
|
2020-03-10 18:46:57 +00:00
|
|
|
m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
|
2019-07-27 19:09:43 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
m_treebook->AddPage( new wxPanel( this ), _( "Project" ) );
|
|
|
|
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 );
|
|
|
|
|
2019-07-27 19:09:43 +00:00
|
|
|
// Connect Events
|
|
|
|
m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
|
|
|
|
wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this );
|
2020-03-10 18:46:57 +00:00
|
|
|
|
|
|
|
FinishDialogSettings();
|
2019-07-27 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_BOARD_SETUP::~DIALOG_BOARD_SETUP()
|
|
|
|
{
|
|
|
|
m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
|
|
|
|
wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_BOARD_SETUP::OnPageChange( wxBookCtrlEvent& event )
|
|
|
|
{
|
|
|
|
if( event.GetSelection() == m_physicalStackupPage )
|
|
|
|
m_physicalStackup->OnLayersOptionsChanged( m_layers->GetUILayerMask() );
|
2020-03-10 18:46:57 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
2020-03-26 11:02:59 +00:00
|
|
|
// Work around an OSX bug where the wxGrid children don't get placed correctly until
|
|
|
|
// the first resize event
|
|
|
|
int page = event.GetSelection();
|
|
|
|
|
|
|
|
if( m_macHack[ page ] )
|
2020-03-10 18:46:57 +00:00
|
|
|
{
|
2020-03-26 11:02:59 +00:00
|
|
|
wxSize pageSize = m_treebook->GetPage( page )->GetSize();
|
|
|
|
pageSize.x -= 1;
|
|
|
|
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
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Run Import Settings... action
|
|
|
|
void DIALOG_BOARD_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ) );
|
|
|
|
|
|
|
|
BOARD* otherBoard = new BOARD();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
otherBoard = pi->Load( boardFn.GetFullPath(), nullptr, nullptr );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
if( ioe.Problem() != wxT( "CANCEL" ) )
|
|
|
|
{
|
|
|
|
wxString msg =
|
|
|
|
wxString::Format( _( "Error loading board file:\n%s" ), boardFn.GetFullPath() );
|
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
otherBoard->SetProject( otherPrj );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
if( importDlg.m_LayersOpt->GetValue() )
|
2020-05-31 21:42:04 +00:00
|
|
|
m_layers->ImportSettingsFrom( otherBoard );
|
2018-04-28 15:22:25 +00:00
|
|
|
if( importDlg.m_TextAndGraphicsOpt->GetValue() )
|
2020-05-31 21:42:04 +00:00
|
|
|
m_textAndGraphics->ImportSettingsFrom( otherBoard );
|
2018-04-28 15:22:25 +00:00
|
|
|
if( importDlg.m_ConstraintsOpt->GetValue() )
|
2020-05-31 21:42:04 +00:00
|
|
|
m_constraints->ImportSettingsFrom( otherBoard );
|
2018-04-28 15:22:25 +00:00
|
|
|
if( importDlg.m_NetclassesOpt->GetValue() )
|
2020-05-31 21:42:04 +00:00
|
|
|
m_netclasses->ImportSettingsFrom( otherBoard );
|
2019-03-07 04:55:14 +00:00
|
|
|
if( importDlg.m_TracksAndViasOpt->GetValue() )
|
2020-05-31 21:42:04 +00:00
|
|
|
m_tracksAndVias->ImportSettingsFrom( otherBoard );
|
2018-04-28 15:22:25 +00:00
|
|
|
if( importDlg.m_MaskAndPasteOpt->GetValue() )
|
2020-05-31 21:42:04 +00:00
|
|
|
m_maskAndPaste->ImportSettingsFrom( otherBoard );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2019-07-27 19:09:43 +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
|
|
|
|
//
|
|
|
|
// Note also currently only the list of enabled layers can be imported, because
|
|
|
|
// we import settings from a .pro project file, not the settings inside
|
|
|
|
// a board, and info only living in the board is not imported.
|
2020-05-31 21:42:04 +00:00
|
|
|
// TODO: Add import of physical settings now that we are actually loading the board here
|
2019-07-27 19:09:43 +00:00
|
|
|
if( importDlg.m_LayersOpt->GetValue() )
|
2020-05-31 21:42:04 +00:00
|
|
|
m_physicalStackup->ImportSettingsFrom( otherBoard );
|
2019-07-27 19:09:43 +00:00
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
if( importDlg.m_SeveritiesOpt->GetValue() )
|
2020-05-31 21:42:04 +00:00
|
|
|
m_severities->ImportSettingsFrom( otherBoard->GetDesignSettings().m_DRCSeverities );
|
|
|
|
|
|
|
|
otherBoard->ClearProject();
|
|
|
|
|
|
|
|
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
|
|
|
}
|