2011-10-13 19:56:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-01 07:19:31 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2017-11-12 00:31:38 +00:00
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
|
2021-06-03 15:41:26 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-13 19:56:32 +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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-07-07 01:53:12 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2020-12-16 13:31:32 +00:00
|
|
|
#include <tools/pcb_selection_tool.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbplot.h>
|
2020-07-08 02:21:45 +00:00
|
|
|
#include <pcb_painter.h>
|
2021-06-09 01:56:00 +00:00
|
|
|
#include <project.h>
|
2020-07-11 17:42:00 +00:00
|
|
|
#include <widgets/appearance_controls.h>
|
2020-07-07 01:53:12 +00:00
|
|
|
#include <widgets/panel_selection_filter.h>
|
2020-07-08 02:21:45 +00:00
|
|
|
#include <project/net_settings.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <project/project_file.h>
|
2020-07-07 01:53:12 +00:00
|
|
|
#include <project/project_local_settings.h>
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
bool PCB_EDIT_FRAME::LoadProjectSettings()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-07-11 01:06:17 +00:00
|
|
|
PROJECT_FILE& project = Prj().GetProjectFile();
|
|
|
|
PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
BASE_SCREEN::m_DrawingSheetFileName = project.m_BoardDrawingSheetFile;
|
2013-10-13 16:29:20 +00:00
|
|
|
|
2021-09-23 15:44:39 +00:00
|
|
|
// Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
|
|
|
|
// If empty, or not existing, the default drawing sheet is loaded.
|
|
|
|
wxString filename = DS_DATA_MODEL::ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
|
|
|
|
Prj().GetProjectPath());
|
2014-12-23 13:01:59 +00:00
|
|
|
|
2021-05-01 18:11:16 +00:00
|
|
|
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
|
2021-06-26 11:33:37 +00:00
|
|
|
ShowInfoBarError( _( "Error loading drawing sheet." ), true );
|
2013-05-20 14:49:20 +00:00
|
|
|
|
2020-07-11 17:42:00 +00:00
|
|
|
// Load render settings that aren't stored in PCB_DISPLAY_OPTIONS
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NET_SETTINGS>& netSettings = project.NetSettings();
|
|
|
|
KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings();
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );
|
2020-07-11 17:42:00 +00:00
|
|
|
|
2022-10-01 23:53:39 +00:00
|
|
|
NETINFO_LIST& nets = GetBoard()->GetNetInfo();
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::set<int>& hiddenNets = renderSettings->GetHiddenNets();
|
2020-07-11 17:42:00 +00:00
|
|
|
hiddenNets.clear();
|
2020-07-08 02:21:45 +00:00
|
|
|
|
2020-07-11 01:06:17 +00:00
|
|
|
for( const wxString& hidden : localSettings.m_HiddenNets )
|
|
|
|
{
|
2022-10-01 23:53:39 +00:00
|
|
|
if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
|
|
|
|
hiddenNets.insert( net->GetNetCode() );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( NETINFO_ITEM* net : nets )
|
|
|
|
{
|
|
|
|
if( localSettings.m_HiddenNetclasses.count( net->GetNetClass()->GetName() ) )
|
2020-12-08 13:02:08 +00:00
|
|
|
hiddenNets.insert( net->GetNetCode() );
|
2020-07-11 01:06:17 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::map<int, KIGFX::COLOR4D>& netColors = renderSettings->GetNetColorMap();
|
2020-07-11 17:42:00 +00:00
|
|
|
netColors.clear();
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& [ netname, color ] : netSettings->m_NetColorAssignments )
|
2020-07-11 17:42:00 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( color != COLOR4D::UNSPECIFIED )
|
|
|
|
{
|
|
|
|
if( NETINFO_ITEM* net = GetBoard()->GetNetInfo().GetNetItem( netname ) )
|
|
|
|
netColors[ net->GetNetCode() ] = color;
|
|
|
|
}
|
2020-07-11 17:42:00 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::map<wxString, KIGFX::COLOR4D>& netclassColors = renderSettings->GetNetclassColorMap();
|
2020-07-11 17:42:00 +00:00
|
|
|
netclassColors.clear();
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& [ name, netclass ] : netSettings->m_NetClasses )
|
|
|
|
netclassColors[ name ] = netclass->GetPcbColor();
|
2020-07-11 17:42:00 +00:00
|
|
|
|
|
|
|
m_appearancePanel->SetUserLayerPresets( project.m_LayerPresets );
|
2021-10-24 22:07:06 +00:00
|
|
|
m_appearancePanel->SetUserViewports( project.m_Viewports );
|
2020-07-07 01:53:12 +00:00
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
|
2020-07-07 01:53:12 +00:00
|
|
|
|
|
|
|
filterOpts = localSettings.m_SelectionFilter;
|
|
|
|
m_selectionFilterPanel->SetCheckboxesFromFilter( filterOpts );
|
|
|
|
|
2020-07-11 17:40:23 +00:00
|
|
|
PCB_DISPLAY_OPTIONS opts = GetDisplayOptions();
|
|
|
|
opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay;
|
2020-07-11 17:42:00 +00:00
|
|
|
opts.m_NetColorMode = localSettings.m_NetColorMode;
|
|
|
|
opts.m_TrackOpacity = localSettings.m_TrackOpacity;
|
|
|
|
opts.m_ViaOpacity = localSettings.m_ViaOpacity;
|
|
|
|
opts.m_PadOpacity = localSettings.m_PadOpacity;
|
|
|
|
opts.m_ZoneOpacity = localSettings.m_ZoneOpacity;
|
2020-12-29 22:19:01 +00:00
|
|
|
opts.m_ZoneDisplayMode = localSettings.m_ZoneDisplayMode;
|
2022-06-27 18:07:52 +00:00
|
|
|
opts.m_ImageOpacity = localSettings.m_ImageOpacity;
|
2021-03-14 15:41:56 +00:00
|
|
|
|
|
|
|
// No refresh here: callers of LoadProjectSettings refresh later
|
|
|
|
SetDisplayOptions( opts, false );
|
2020-07-11 17:40:23 +00:00
|
|
|
|
2021-01-07 04:11:06 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = GetDesignSettings();
|
|
|
|
bds.m_UseConnectedTrackWidth = localSettings.m_AutoTrackWidth;
|
|
|
|
|
2020-08-24 02:01:14 +00:00
|
|
|
wxFileName fn( GetCurrentFileName() );
|
|
|
|
fn.MakeRelativeTo( Prj().GetProjectPath() );
|
|
|
|
LoadWindowState( fn.GetFullPath() );
|
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-02-19 00:35:45 +00:00
|
|
|
|
2020-02-28 00:05:40 +00:00
|
|
|
void PCB_EDIT_FRAME::SaveProjectSettings()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxFileName fn = Prj().GetProjectFullName();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2020-03-04 17:40:28 +00:00
|
|
|
// Check for the filename before checking IsWritable as this
|
|
|
|
// will throw errors on bad names. Here, we just want to not
|
|
|
|
// save the Settings if we don't have a name
|
|
|
|
if( !fn.IsOk() )
|
|
|
|
return;
|
|
|
|
|
2020-07-17 02:56:02 +00:00
|
|
|
if( !fn.IsDirWritable() )
|
2020-02-28 00:05:40 +00:00
|
|
|
return;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2020-07-11 01:06:17 +00:00
|
|
|
PROJECT_FILE& project = Prj().GetProjectFile();
|
|
|
|
PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
|
2010-04-23 14:46:00 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
// TODO: Can this be pulled out of BASE_SCREEN?
|
2021-05-30 22:56:24 +00:00
|
|
|
project.m_BoardDrawingSheetFile = BASE_SCREEN::m_DrawingSheetFileName;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2020-07-11 17:42:00 +00:00
|
|
|
project.m_LayerPresets = m_appearancePanel->GetUserLayerPresets();
|
2021-10-24 22:07:06 +00:00
|
|
|
project.m_Viewports = m_appearancePanel->GetUserViewports();
|
2020-07-11 17:42:00 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
RecordDRCExclusions();
|
2012-02-19 04:02:19 +00:00
|
|
|
|
2020-07-11 17:42:00 +00:00
|
|
|
// Save appearance control settings
|
2020-07-11 17:40:23 +00:00
|
|
|
|
2020-07-11 17:42:00 +00:00
|
|
|
localSettings.m_ActiveLayer = GetActiveLayer();
|
|
|
|
localSettings.m_ActiveLayerPreset = m_appearancePanel->GetActiveLayerPreset();
|
|
|
|
|
|
|
|
const PCB_DISPLAY_OPTIONS& displayOpts = GetDisplayOptions();
|
|
|
|
|
|
|
|
localSettings.m_ContrastModeDisplay = displayOpts.m_ContrastModeDisplay;
|
|
|
|
localSettings.m_NetColorMode = displayOpts.m_NetColorMode;
|
|
|
|
localSettings.m_TrackOpacity = displayOpts.m_TrackOpacity;
|
|
|
|
localSettings.m_ViaOpacity = displayOpts.m_ViaOpacity;
|
|
|
|
localSettings.m_PadOpacity = displayOpts.m_PadOpacity;
|
|
|
|
localSettings.m_ZoneOpacity = displayOpts.m_ZoneOpacity;
|
|
|
|
localSettings.m_ZoneDisplayMode = displayOpts.m_ZoneDisplayMode;
|
2022-06-27 18:07:52 +00:00
|
|
|
localSettings.m_ImageOpacity = displayOpts.m_ImageOpacity;
|
2020-07-11 17:42:00 +00:00
|
|
|
|
2021-01-07 04:11:06 +00:00
|
|
|
// Save Design settings
|
|
|
|
const BOARD_DESIGN_SETTINGS& bds = GetDesignSettings();
|
|
|
|
localSettings.m_AutoTrackWidth = bds.m_UseConnectedTrackWidth;
|
|
|
|
|
2020-07-11 17:42:00 +00:00
|
|
|
// Save render settings that aren't stored in PCB_DISPLAY_OPTIONS
|
2020-07-11 17:40:23 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NET_SETTINGS>& netSettings = project.NetSettings();
|
|
|
|
KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings();
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );
|
|
|
|
NETINFO_LIST& nets = GetBoard()->GetNetInfo();
|
2020-07-11 01:06:17 +00:00
|
|
|
|
|
|
|
localSettings.m_HiddenNets.clear();
|
2020-07-07 01:53:12 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( int netcode : renderSettings->GetHiddenNets() )
|
2020-07-11 01:06:17 +00:00
|
|
|
{
|
|
|
|
if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
|
|
|
|
localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
|
|
|
|
}
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
netSettings->m_NetColorAssignments.clear();
|
2020-07-11 17:42:00 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& [ netcode, color ] : renderSettings->GetNetColorMap() )
|
2020-07-11 17:42:00 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
|
|
|
|
netSettings->m_NetColorAssignments[ net->GetNetname() ] = color;
|
2020-07-11 17:42:00 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
std::map<wxString, KIGFX::COLOR4D>& netclassColors = renderSettings->GetNetclassColorMap();
|
2020-07-11 17:42:00 +00:00
|
|
|
|
|
|
|
// NOTE: this assumes netclasses will have already been updated, which I think is the case
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& [ name, netclass ] : netSettings->m_NetClasses )
|
2020-07-11 17:42:00 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( netclassColors.count( name ) )
|
|
|
|
netclass->SetPcbColor( netclassColors.at( name ) );
|
2020-07-11 17:42:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* selTool = GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
|
|
|
|
|
|
|
|
localSettings.m_SelectionFilter = filterOpts;
|
2020-07-07 01:53:12 +00:00
|
|
|
|
2021-02-04 00:05:46 +00:00
|
|
|
/**
|
|
|
|
* The below automatically saves the project on exit, which is what we want to do if the project
|
|
|
|
* already exists. If the project doesn't already exist, we don't want to create it through
|
|
|
|
* this function call, because this will happen automatically when the user exits even if they
|
|
|
|
* didn't save a new board with a valid filename (usually an imported board).
|
|
|
|
*
|
|
|
|
* The explicit save action in PCB_EDIT_FRAME::SavePcbFile will call SaveProject directly,
|
|
|
|
* so if the user does choose to save the board, the project file will get created then.
|
|
|
|
*/
|
2021-04-22 01:27:23 +00:00
|
|
|
if( !Prj().IsNullProject() && fn.Exists() )
|
2020-08-25 02:17:21 +00:00
|
|
|
GetSettingsManager()->SaveProject();
|
2010-04-23 14:46:00 +00:00
|
|
|
}
|