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 <dick@softplc.com>
6  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
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 <panel_hotkeys_editor.h>
29 #include <panel_edit_options.h>
31 #include <panel_display_options.h>
34 #include <tool/tool_manager.h>
36 #include <board_design_settings.h>
38 #include <pcbplot.h>
39 #include <pcb_painter.h>
40 #include <project.h>
41 #include <invoke_pcb_dialog.h>
43 #include <widgets/paged_dialog.h>
45 #include <project/net_settings.h>
46 #include <project/project_file.h>
48 #include <wx/treebook.h>
49 
50 
51 
53  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
54 {
55  wxTreebook* book = aParent->GetTreebook();
56 
57  book->AddPage( new wxPanel( book ), _( "PCB Editor" ) );
58  book->AddSubPage( new PANEL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
59  book->AddSubPage( new PANEL_EDIT_OPTIONS( this, aParent ), _( "Editing Options" ) );
60  book->AddSubPage( new PANEL_PCBNEW_COLOR_SETTINGS( this, book ), _( "Colors" ) );
61  book->AddSubPage( new PANEL_PCBNEW_ACTION_PLUGINS( this, aParent ), _( "Action Plugins" ) );
62  book->AddSubPage( new PANEL_PCBNEW_DISPLAY_ORIGIN( this, aParent ), _( "Origins & Axes" ) );
63 
64  aHotkeysPanel->AddHotKeys( GetToolManager() );
65 }
66 
67 
69 {
71  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
72 
73  BASE_SCREEN::m_DrawingSheetFileName = project.m_BoardDrawingSheetFile;
74 
75  // Load the drawing sheet description file, from the filename stored in
76  // BASE_SCREEN::m_DrawingSheetFileName, read in config project file
77  // If empty, or not existing, the default descr is loaded
79  Prj().GetProjectPath() );
80 
81  if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
82  {
83  ShowInfoBarError( _( "Error loading drawing sheet." ), true );
84  }
85 
86  // Load render settings that aren't stored in PCB_DISPLAY_OPTIONS
87 
88  NET_SETTINGS& netSettings = project.NetSettings();
89  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
90 
91  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
92  GetCanvas()->GetView()->GetPainter()->GetSettings() );
93 
94  std::set<int>& hiddenNets = rs->GetHiddenNets();
95  hiddenNets.clear();
96 
97  for( const wxString& hidden : localSettings.m_HiddenNets )
98  {
99  if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
100  hiddenNets.insert( net->GetNetCode() );
101  }
102 
103  std::map<int, KIGFX::COLOR4D>& netColors = rs->GetNetColorMap();
104  netColors.clear();
105 
106  for( const auto& pair : netSettings.m_PcbNetColors )
107  {
108  if( pair.second == COLOR4D::UNSPECIFIED )
109  continue;
110 
111  if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
112  netColors[ net->GetNetCode() ] = pair.second;
113  }
114 
115  std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
116  netclassColors.clear();
117 
118  for( const auto& pair : netSettings.m_NetClasses )
119  netclassColors[pair.first] = pair.second->GetPcbColor();
120 
121  m_appearancePanel->SetUserLayerPresets( project.m_LayerPresets );
122 
124  SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
125 
126  filterOpts = localSettings.m_SelectionFilter;
128 
130  opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay;
131  opts.m_NetColorMode = localSettings.m_NetColorMode;
132  opts.m_RatsnestMode = localSettings.m_RatsnestMode;
133  opts.m_TrackOpacity = localSettings.m_TrackOpacity;
134  opts.m_ViaOpacity = localSettings.m_ViaOpacity;
135  opts.m_PadOpacity = localSettings.m_PadOpacity;
136  opts.m_ZoneOpacity = localSettings.m_ZoneOpacity;
137  opts.m_ZoneDisplayMode = localSettings.m_ZoneDisplayMode;
138 
139  // No refresh here: callers of LoadProjectSettings refresh later
140  SetDisplayOptions( opts, false );
141 
143  bds.m_UseConnectedTrackWidth = localSettings.m_AutoTrackWidth;
144 
145  wxFileName fn( GetCurrentFileName() );
146  fn.MakeRelativeTo( Prj().GetProjectPath() );
147  LoadWindowState( fn.GetFullPath() );
148 
149  return true;
150 }
151 
152 
154 {
155  wxFileName fn = Prj().GetProjectFullName();
156 
157  // Check for the filename before checking IsWritable as this
158  // will throw errors on bad names. Here, we just want to not
159  // save the Settings if we don't have a name
160  if( !fn.IsOk() )
161  return;
162 
163  if( !fn.IsDirWritable() )
164  return;
165 
167  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
168 
169  // TODO: Can this be pulled out of BASE_SCREEN?
170  project.m_BoardDrawingSheetFile = BASE_SCREEN::m_DrawingSheetFileName;
171 
172  project.m_LayerPresets = m_appearancePanel->GetUserLayerPresets();
173 
175 
176  // Save appearance control settings
177 
178  localSettings.m_ActiveLayer = GetActiveLayer();
180 
181  const PCB_DISPLAY_OPTIONS& displayOpts = GetDisplayOptions();
182 
183  localSettings.m_ContrastModeDisplay = displayOpts.m_ContrastModeDisplay;
184  localSettings.m_NetColorMode = displayOpts.m_NetColorMode;
185  localSettings.m_RatsnestMode = displayOpts.m_RatsnestMode;
186  localSettings.m_TrackOpacity = displayOpts.m_TrackOpacity;
187  localSettings.m_ViaOpacity = displayOpts.m_ViaOpacity;
188  localSettings.m_PadOpacity = displayOpts.m_PadOpacity;
189  localSettings.m_ZoneOpacity = displayOpts.m_ZoneOpacity;
190  localSettings.m_ZoneDisplayMode = displayOpts.m_ZoneDisplayMode;
191 
192  // Save Design settings
194  localSettings.m_AutoTrackWidth = bds.m_UseConnectedTrackWidth;
195 
196  // Save render settings that aren't stored in PCB_DISPLAY_OPTIONS
197 
198  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
199  GetCanvas()->GetView()->GetPainter()->GetSettings() );
200 
201  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
202 
203  localSettings.m_HiddenNets.clear();
204 
205  for( int netcode : rs->GetHiddenNets() )
206  {
207  if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
208  localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
209  }
210 
211  NET_SETTINGS& netSettings = project.NetSettings();
212 
213  netSettings.m_PcbNetColors.clear();
214 
215  for( const std::pair<const int, KIGFX::COLOR4D>& pair : rs->GetNetColorMap() )
216  {
217  if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
218  netSettings.m_PcbNetColors[net->GetNetname()] = pair.second;
219  }
220 
221  std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
222 
223  // NOTE: this assumes netclasses will have already been updated, which I think is the case
224  for( const std::pair<const wxString, NETCLASSPTR>& pair : netSettings.m_NetClasses )
225  {
226  if( netclassColors.count( pair.first ) )
227  pair.second->SetPcbColor( netclassColors.at( pair.first ) );
228  }
229 
231  SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
232 
233  localSettings.m_SelectionFilter = filterOpts;
234 
244  if( !Prj().IsNullProject() && fn.Exists() )
246 }
std::set< int > & GetHiddenNets()
Definition: pcb_painter.h:187
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
SETTINGS_MANAGER * GetSettingsManager() const
double m_TrackOpacity
Opacity override for all tracks.
std::map< wxString, KIGFX::COLOR4D > m_PcbNetColors
A map of fully-qualified net names to colors used in the board context.
Definition: net_settings.h:52
APPEARANCE_CONTROLS * m_appearancePanel
double m_TrackOpacity
Opacity override for all tracks.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
How zones are drawn.
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:145
std::map< wxString, KIGFX::COLOR4D > & GetNetclassColorMap()
Definition: pcb_painter.h:183
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
double m_ViaOpacity
Opacity override for all types of via.
The project local settings are things that are attached to a particular project, but also might be pa...
double m_ViaOpacity
Opacity override for all types of via.
bool LoadProjectSettings()
Load the current project's file configuration settings which are pertinent to this PCB_EDIT_FRAME ins...
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:684
void AddHotKeys(TOOL_MANAGER *aToolMgr)
NET_COLOR_MODE m_NetColorMode
The current net color mode.
PCB_LAYER_ID m_ActiveLayer
The current (active) board layer for editing.
void RecordDRCExclusions()
Scan existing markers and record data from any that are Excluded.
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
void LoadWindowState(const wxString &aFileName)
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:64
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:151
Board plot function definition file.
double m_PadOpacity
Opacity override for SMD pads and PTH.
wxTreebook * GetTreebook()
Definition: paged_dialog.h:37
virtual PCB_LAYER_ID GetActiveLayer() const
PCB specific render settings.
Definition: pcb_painter.h:64
RATSNEST_MODE m_RatsnestMode
Ratsnest draw mode (all layers vs only visible layers)
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aRefresh=true)
Updates the current display options from the given options struct.
Container for display options like enable/disable some optional drawings.
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
void SetCheckboxesFromFilter(SELECTION_FILTER_OPTIONS &aOptions)
NETCLASSES m_NetClasses
Definition: net_settings.h:40
wxString m_ActiveLayerPreset
The name of a LAYER_PRESET that is currently activated (or blank if none)
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:315
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
void SaveProjectSettings() override
Save changes to the project settings to the project (.pro) file.
RATSNEST_MODE m_RatsnestMode
The current ratsnest draw mode.
#define _(s)
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:32
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
bool m_AutoTrackWidth
The current setting for whether to automatically adjust track widths to match.
This file contains data structures that are saved in the project file or project local settings file ...
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:116
double m_ZoneOpacity
Opacity override for filled zones.
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.
double m_ZoneOpacity
Opacity override for filled zone areas.
Handle the data for a net.
Definition: netinfo.h:64
double m_PadOpacity
Opacity override for SMD pads and PTHs.
HIGH_CONTRAST_MODE m_ContrastModeDisplay
The current contrast mode.
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allow Pcbnew to install its preferences panel into the preferences dialog.
PANEL_SELECTION_FILTER * m_selectionFilterPanel
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
static const wxString MakeFullFileName(const wxString &aShortFileName, const wxString &aProjectPath)
bool SaveProject(const wxString &aFullPath=wxEmptyString)
Saves a loaded project.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
The selection tool: currently supports:
wxString GetActiveLayerPreset() const
std::vector< wxString > m_HiddenNets
A list of netnames that have been manually hidden in the board editor.
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
SELECTION_FILTER_OPTIONS m_SelectionFilter
State of the selection filter widget.
SELECTION_FILTER_OPTIONS & GetFilter()
Set up handlers for various events.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
Definition: pcb_painter.h:185
BOARD * GetBoard() const
NETINFO_ITEM * GetNetItem(int aNetCode) const
wxString GetCurrentFileName() const override
Get the full filename + path of the currently opened file in the frame.
NET_COLOR_MODE m_NetColorMode
How to use color overrides on specific nets and netclasses.
Container for design settings for a BOARD object.