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>
|
2020-08-18 14:17:16 +00:00
|
|
|
* Copyright (C) 1992-2020 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>
|
2018-05-14 17:34:18 +00:00
|
|
|
#include <panel_hotkeys_editor.h>
|
2020-06-17 20:45:03 +00:00
|
|
|
#include <panel_edit_options.h>
|
2020-04-24 01:55:20 +00:00
|
|
|
#include <panel_pcbnew_color_settings.h>
|
2020-06-17 20:45:03 +00:00
|
|
|
#include <panel_display_options.h>
|
2018-08-15 09:26:32 +00:00
|
|
|
#include <panel_pcbnew_action_plugins.h>
|
2020-07-07 01:33:03 +00:00
|
|
|
#include <panel_pcbnew_display_origin.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-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>
|
2013-10-13 21:33:58 +00:00
|
|
|
#include <invoke_pcb_dialog.h>
|
2020-07-11 17:42:00 +00:00
|
|
|
#include <widgets/appearance_controls.h>
|
2018-04-28 15:22:25 +00:00
|
|
|
#include <widgets/paged_dialog.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
|
|
|
|
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
void PCB_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent,
|
|
|
|
PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
|
2018-05-14 17:34:18 +00:00
|
|
|
{
|
2020-08-29 19:52:39 +00:00
|
|
|
wxTreebook* book = aParent->GetTreebook();
|
2018-07-15 23:15:48 +00:00
|
|
|
|
2021-02-18 15:49:35 +00:00
|
|
|
book->AddPage( new wxPanel( book ), _( "PCB Editor" ) );
|
2020-06-17 20:45:03 +00:00
|
|
|
book->AddSubPage( new PANEL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
|
|
|
|
book->AddSubPage( new PANEL_EDIT_OPTIONS( this, aParent ), _( "Editing Options" ) );
|
2020-08-11 02:01:04 +00:00
|
|
|
book->AddSubPage( new PANEL_PCBNEW_COLOR_SETTINGS( this, book ), _( "Colors" ) );
|
2018-08-15 09:26:32 +00:00
|
|
|
#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
|
|
|
|
book->AddSubPage( new PANEL_PCBNEW_ACTION_PLUGINS( this, aParent ), _( "Action Plugins" ) );
|
|
|
|
#endif
|
2020-07-07 01:33:03 +00:00
|
|
|
book->AddSubPage( new PANEL_PCBNEW_DISPLAY_ORIGIN( this, aParent ), _( "Origins & Axes" ) );
|
2019-11-08 08:42:33 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
aHotkeysPanel->AddHotKeys( GetToolManager() );
|
2018-05-14 17:34:18 +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
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
BASE_SCREEN::m_PageLayoutDescrFileName = project.m_BoardPageLayoutDescrFile;
|
2013-10-13 16:29:20 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
// Load the drawing sheet description file, from the filename stored in
|
2013-07-19 18:27:22 +00:00
|
|
|
// BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
|
2014-12-31 12:31:19 +00:00
|
|
|
// If empty, or not existing, the default descr is loaded
|
2021-02-22 23:47:17 +00:00
|
|
|
wxString filename = DS_DATA_MODEL::MakeFullFileName( BASE_SCREEN::m_PageLayoutDescrFileName,
|
2019-05-25 11:05:39 +00:00
|
|
|
Prj().GetProjectPath() );
|
2014-12-23 13:01:59 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename );
|
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
|
|
|
|
|
|
|
|
NET_SETTINGS& netSettings = project.NetSettings();
|
|
|
|
NETINFO_LIST& nets = GetBoard()->GetNetInfo();
|
|
|
|
|
2020-07-08 02:21:45 +00:00
|
|
|
KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
|
|
|
|
GetCanvas()->GetView()->GetPainter()->GetSettings() );
|
|
|
|
|
2020-07-11 17:42:00 +00:00
|
|
|
std::set<int>& hiddenNets = rs->GetHiddenNets();
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
|
2020-12-08 13:02:08 +00:00
|
|
|
hiddenNets.insert( net->GetNetCode() );
|
2020-07-11 01:06:17 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 17:42:00 +00:00
|
|
|
std::map<int, KIGFX::COLOR4D>& netColors = rs->GetNetColorMap();
|
|
|
|
netColors.clear();
|
|
|
|
|
|
|
|
for( const auto& pair : netSettings.m_PcbNetColors )
|
|
|
|
{
|
2020-08-15 22:49:56 +00:00
|
|
|
if( pair.second == COLOR4D::UNSPECIFIED )
|
|
|
|
continue;
|
|
|
|
|
2020-07-11 17:42:00 +00:00
|
|
|
if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
|
2020-12-08 13:02:08 +00:00
|
|
|
netColors[ net->GetNetCode() ] = pair.second;
|
2020-07-11 17:42:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
|
|
|
|
netclassColors.clear();
|
|
|
|
|
|
|
|
for( const auto& pair : netSettings.m_NetClasses )
|
2020-09-03 17:54:14 +00:00
|
|
|
netclassColors[pair.first] = pair.second->GetPcbColor();
|
2020-07-11 17:42:00 +00:00
|
|
|
|
|
|
|
m_appearancePanel->SetUserLayerPresets( project.m_LayerPresets );
|
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;
|
2020-09-07 20:43:31 +00:00
|
|
|
opts.m_RatsnestMode = localSettings.m_RatsnestMode;
|
2020-07-11 17:42:00 +00:00
|
|
|
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;
|
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?
|
2020-06-08 02:19:46 +00:00
|
|
|
project.m_BoardPageLayoutDescrFile = BASE_SCREEN::m_PageLayoutDescrFileName;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2020-07-11 17:42:00 +00:00
|
|
|
project.m_LayerPresets = m_appearancePanel->GetUserLayerPresets();
|
|
|
|
|
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;
|
2020-09-07 20:43:31 +00:00
|
|
|
localSettings.m_RatsnestMode = displayOpts.m_RatsnestMode;
|
2020-07-11 17:42:00 +00:00
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
2020-07-11 01:06:17 +00:00
|
|
|
KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
|
|
|
|
GetCanvas()->GetView()->GetPainter()->GetSettings() );
|
2020-07-07 01:53:12 +00:00
|
|
|
|
2020-07-11 01:06:17 +00:00
|
|
|
NETINFO_LIST& nets = GetBoard()->GetNetInfo();
|
|
|
|
|
|
|
|
localSettings.m_HiddenNets.clear();
|
2020-07-07 01:53:12 +00:00
|
|
|
|
2020-07-11 01:06:17 +00:00
|
|
|
for( int netcode : rs->GetHiddenNets() )
|
|
|
|
{
|
|
|
|
if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
|
|
|
|
localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
|
|
|
|
}
|
|
|
|
|
2020-07-11 17:42:00 +00:00
|
|
|
NET_SETTINGS& netSettings = project.NetSettings();
|
|
|
|
|
|
|
|
netSettings.m_PcbNetColors.clear();
|
|
|
|
|
2020-09-03 17:54:14 +00:00
|
|
|
for( const std::pair<const int, KIGFX::COLOR4D>& pair : rs->GetNetColorMap() )
|
2020-07-11 17:42:00 +00:00
|
|
|
{
|
|
|
|
if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
|
|
|
|
netSettings.m_PcbNetColors[net->GetNetname()] = pair.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
|
|
|
|
|
|
|
|
// NOTE: this assumes netclasses will have already been updated, which I think is the case
|
2020-09-03 17:54:14 +00:00
|
|
|
for( const std::pair<const wxString, NETCLASSPTR>& pair : netSettings.m_NetClasses )
|
2020-07-11 17:42:00 +00:00
|
|
|
{
|
2020-09-03 17:54:14 +00:00
|
|
|
if( netclassColors.count( pair.first ) )
|
2020-07-11 17:42:00 +00:00
|
|
|
pair.second->SetPcbColor( netclassColors.at( pair.first ) );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|