KiCad PCB EDA Suite
pcbnew_config.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2012 Wayne Stambaugh <[email protected]>
7 * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <pcb_edit_frame.h>
28#include <tool/tool_manager.h>
32#include <pcbplot.h>
33#include <pcb_painter.h>
34#include <project.h>
40
41
43{
45 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
46
47 BASE_SCREEN::m_DrawingSheetFileName = project.m_BoardDrawingSheetFile;
48
49 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
50 // If empty, or not existing, the default drawing sheet is loaded.
52 Prj().GetProjectPath());
53
54 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
55 ShowInfoBarError( _( "Error loading drawing sheet." ), true );
56
57 // Load render settings that aren't stored in PCB_DISPLAY_OPTIONS
58
59 std::shared_ptr<NET_SETTINGS>& netSettings = project.NetSettings();
61 KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );
62
63 NETINFO_LIST& nets = GetBoard()->GetNetInfo();
64
65 std::set<int>& hiddenNets = renderSettings->GetHiddenNets();
66 hiddenNets.clear();
67
68 for( const wxString& hidden : localSettings.m_HiddenNets )
69 {
70 if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
71 hiddenNets.insert( net->GetNetCode() );
72 }
73
74 for( NETINFO_ITEM* net : nets )
75 {
76 if( localSettings.m_HiddenNetclasses.count( net->GetNetClass()->GetName() ) )
77 hiddenNets.insert( net->GetNetCode() );
78 }
79
80 std::map<int, KIGFX::COLOR4D>& netColors = renderSettings->GetNetColorMap();
81 netColors.clear();
82
83 for( const auto& [ netname, color ] : netSettings->m_NetColorAssignments )
84 {
85 if( color != COLOR4D::UNSPECIFIED )
86 {
87 if( NETINFO_ITEM* net = GetBoard()->GetNetInfo().GetNetItem( netname ) )
88 netColors[ net->GetNetCode() ] = color;
89 }
90 }
91
92 std::map<wxString, KIGFX::COLOR4D>& netclassColors = renderSettings->GetNetclassColorMap();
93 netclassColors.clear();
94
95 for( const auto& [ name, netclass ] : netSettings->m_NetClasses )
96 netclassColors[ name ] = netclass->GetPcbColor();
97
100
102 SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
103
104 filterOpts = localSettings.m_SelectionFilter;
106
108 opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay;
109 opts.m_NetColorMode = localSettings.m_NetColorMode;
110 opts.m_TrackOpacity = localSettings.m_TrackOpacity;
111 opts.m_ViaOpacity = localSettings.m_ViaOpacity;
112 opts.m_PadOpacity = localSettings.m_PadOpacity;
113 opts.m_ZoneOpacity = localSettings.m_ZoneOpacity;
114 opts.m_ZoneDisplayMode = localSettings.m_ZoneDisplayMode;
115 opts.m_ImageOpacity = localSettings.m_ImageOpacity;
116
117 // No refresh here: callers of LoadProjectSettings refresh later
118 SetDisplayOptions( opts, false );
119
121 bds.m_UseConnectedTrackWidth = localSettings.m_AutoTrackWidth;
122
123 wxFileName fn( GetCurrentFileName() );
124 fn.MakeRelativeTo( Prj().GetProjectPath() );
125 LoadWindowState( fn.GetFullPath() );
126
127 return true;
128}
129
130
132{
133 wxFileName fn = Prj().GetProjectFullName();
134
135 // Check for the filename before checking IsWritable as this
136 // will throw errors on bad names. Here, we just want to not
137 // save the Settings if we don't have a name
138 if( !fn.IsOk() )
139 return;
140
141 if( !fn.IsDirWritable() )
142 return;
143
145 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
146
147 // TODO: Can this be pulled out of BASE_SCREEN?
148 project.m_BoardDrawingSheetFile = BASE_SCREEN::m_DrawingSheetFileName;
149
152
154
155 // Save appearance control settings
156
157 localSettings.m_ActiveLayer = GetActiveLayer();
159
160 const PCB_DISPLAY_OPTIONS& displayOpts = GetDisplayOptions();
161
162 localSettings.m_ContrastModeDisplay = displayOpts.m_ContrastModeDisplay;
163 localSettings.m_NetColorMode = displayOpts.m_NetColorMode;
164 localSettings.m_TrackOpacity = displayOpts.m_TrackOpacity;
165 localSettings.m_ViaOpacity = displayOpts.m_ViaOpacity;
166 localSettings.m_PadOpacity = displayOpts.m_PadOpacity;
167 localSettings.m_ZoneOpacity = displayOpts.m_ZoneOpacity;
168 localSettings.m_ZoneDisplayMode = displayOpts.m_ZoneDisplayMode;
169 localSettings.m_ImageOpacity = displayOpts.m_ImageOpacity;
170
171 // Save Design settings
173 localSettings.m_AutoTrackWidth = bds.m_UseConnectedTrackWidth;
174
175 // Save render settings that aren't stored in PCB_DISPLAY_OPTIONS
176
177 std::shared_ptr<NET_SETTINGS>& netSettings = project.NetSettings();
179 KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );
180 NETINFO_LIST& nets = GetBoard()->GetNetInfo();
181
182 localSettings.m_HiddenNets.clear();
183
184 for( int netcode : renderSettings->GetHiddenNets() )
185 {
186 if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
187 localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
188 }
189
190 netSettings->m_NetColorAssignments.clear();
191
192 for( const auto& [ netcode, color ] : renderSettings->GetNetColorMap() )
193 {
194 if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
195 netSettings->m_NetColorAssignments[ net->GetNetname() ] = color;
196 }
197
198 std::map<wxString, KIGFX::COLOR4D>& netclassColors = renderSettings->GetNetclassColorMap();
199
200 // NOTE: this assumes netclasses will have already been updated, which I think is the case
201 for( const auto& [ name, netclass ] : netSettings->m_NetClasses )
202 {
203 if( netclassColors.count( name ) )
204 netclass->SetPcbColor( netclassColors.at( name ) );
205 }
206
208 SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
209
210 localSettings.m_SelectionFilter = filterOpts;
211
221 if( !Prj().IsNullProject() && fn.Exists() )
223}
int color
Definition: DXF_plotter.cpp:57
const char * name
Definition: DXF_plotter.cpp:56
void SetUserLayerPresets(std::vector< LAYER_PRESET > &aPresetList)
std::vector< LAYER_PRESET > GetUserLayerPresets() const
Update the current layer presets from those saved in the project file.
void SetUserViewports(std::vector< VIEWPORT > &aPresetList)
wxString GetActiveLayerPreset() const
std::vector< VIEWPORT > GetUserViewports() const
Update the current viewports from those saved in the project file.
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
Container for design settings for a BOARD object.
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:765
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
static const wxString ResolvePath(const wxString &aPath, const wxString &aProjectPath)
Resolve a path which might be project-relative or contain env variable references.
void LoadWindowState(const wxString &aFileName)
SETTINGS_MANAGER * GetSettingsManager() const
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Definition: pcb_painter.h:72
std::set< int > & GetHiddenNets()
Definition: pcb_painter.h:118
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
Definition: pcb_painter.h:116
std::map< wxString, KIGFX::COLOR4D > & GetNetclassColorMap()
Definition: pcb_painter.h:114
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:213
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Handle the data for a net.
Definition: netinfo.h:67
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:333
NETINFO_ITEM * GetNetItem(int aNetCode) const
void SetCheckboxesFromFilter(SELECTION_FILTER_OPTIONS &aOptions)
APPEARANCE_CONTROLS * m_appearancePanel
PANEL_SELECTION_FILTER * m_selectionFilterPanel
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aRefresh=true)
Updates the current display options from the given options struct.
double m_TrackOpacity
Opacity override for all tracks.
double m_ZoneOpacity
Opacity override for filled zone areas.
double m_ImageOpacity
Opacity override for user images.
double m_PadOpacity
Opacity override for SMD pads and PTHs.
double m_ViaOpacity
Opacity override for all types of via.
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
NET_COLOR_MODE m_NetColorMode
How to use color overrides on specific nets and netclasses.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void SaveProjectSettings() override
Save changes to the project settings to the project (.pro) file.
void RecordDRCExclusions()
Scan existing markers and record data from any that are Excluded.
bool LoadProjectSettings()
Load the current project's file configuration settings which are pertinent to this PCB_EDIT_FRAME ins...
wxString GetCurrentFileName() const override
Get the full filename + path of the currently opened file in the frame.
The selection tool: currently supports:
SELECTION_FILTER_OPTIONS & GetFilter()
Set up handlers for various events.
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:65
The project local settings are things that are attached to a particular project, but also might be pa...
SELECTION_FILTER_OPTIONS m_SelectionFilter
State of the selection filter widget.
double m_PadOpacity
Opacity override for SMD pads and PTH.
double m_ViaOpacity
Opacity override for all types of via.
wxString m_ActiveLayerPreset
The name of a LAYER_PRESET that is currently activated (or blank if none)
double m_TrackOpacity
Opacity override for all tracks.
double m_ZoneOpacity
Opacity override for filled zones.
bool m_AutoTrackWidth
The current setting for whether to automatically adjust track widths to match.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
How zones are drawn.
PCB_LAYER_ID m_ActiveLayer
The current (active) board layer for editing.
HIGH_CONTRAST_MODE m_ContrastModeDisplay
The current contrast mode.
NET_COLOR_MODE m_NetColorMode
The current net color mode.
std::vector< wxString > m_HiddenNets
A list of netnames that have been manually hidden in the board editor.
std::set< wxString > m_HiddenNetclasses
double m_ImageOpacity
Opacity override for user images.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:120
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:155
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:149
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:138
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Saves a loaded project.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
#define _(s)
This file contains data structures that are saved in the project file or project local settings file ...