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 <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>
43 #include <widgets/paged_dialog.h>
44 #include <project/net_settings.h>
45 #include <project/project_file.h>
47 #include <wx/treebook.h>
48 
49 
50 
52  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
53 {
54  wxTreebook* book = aParent->GetTreebook();
55 
56  book->AddPage( new wxPanel( book ), _( "PCB Editor" ) );
57  book->AddSubPage( new PANEL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
58  book->AddSubPage( new PANEL_EDIT_OPTIONS( this, aParent ), _( "Editing Options" ) );
59  book->AddSubPage( new PANEL_PCBNEW_COLOR_SETTINGS( this, book ), _( "Colors" ) );
60  book->AddSubPage( new PANEL_PCBNEW_ACTION_PLUGINS( this, aParent ), _( "Action Plugins" ) );
61  book->AddSubPage( new PANEL_PCBNEW_DISPLAY_ORIGIN( this, aParent ), _( "Origins & Axes" ) );
62 
63  aHotkeysPanel->AddHotKeys( GetToolManager() );
64 }
65 
66 
68 {
70  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
71 
72  BASE_SCREEN::m_DrawingSheetFileName = project.m_BoardDrawingSheetFile;
73 
74  // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
75  // If empty, or not existing, the default drawing sheet is loaded.
77  Prj().GetProjectPath());
78 
79  if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
80  {
81  ShowInfoBarError( _( "Error loading drawing sheet." ), true );
82  }
83 
84  // Load render settings that aren't stored in PCB_DISPLAY_OPTIONS
85 
86  NET_SETTINGS& netSettings = project.NetSettings();
87  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
88 
89  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
90  GetCanvas()->GetView()->GetPainter()->GetSettings() );
91 
92  std::set<int>& hiddenNets = rs->GetHiddenNets();
93  hiddenNets.clear();
94 
95  for( const wxString& hidden : localSettings.m_HiddenNets )
96  {
97  if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
98  hiddenNets.insert( net->GetNetCode() );
99  }
100 
101  std::map<int, KIGFX::COLOR4D>& netColors = rs->GetNetColorMap();
102  netColors.clear();
103 
104  for( const auto& pair : netSettings.m_PcbNetColors )
105  {
106  if( pair.second == COLOR4D::UNSPECIFIED )
107  continue;
108 
109  if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
110  netColors[ net->GetNetCode() ] = pair.second;
111  }
112 
113  std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
114  netclassColors.clear();
115 
116  for( const auto& pair : netSettings.m_NetClasses )
117  netclassColors[pair.first] = pair.second->GetPcbColor();
118 
119  m_appearancePanel->SetUserLayerPresets( project.m_LayerPresets );
120 
122  SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
123 
124  filterOpts = localSettings.m_SelectionFilter;
126 
128  opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay;
129  opts.m_NetColorMode = localSettings.m_NetColorMode;
130  opts.m_RatsnestMode = localSettings.m_RatsnestMode;
131  opts.m_TrackOpacity = localSettings.m_TrackOpacity;
132  opts.m_ViaOpacity = localSettings.m_ViaOpacity;
133  opts.m_PadOpacity = localSettings.m_PadOpacity;
134  opts.m_ZoneOpacity = localSettings.m_ZoneOpacity;
135  opts.m_ZoneDisplayMode = localSettings.m_ZoneDisplayMode;
136 
137  // No refresh here: callers of LoadProjectSettings refresh later
138  SetDisplayOptions( opts, false );
139 
141  bds.m_UseConnectedTrackWidth = localSettings.m_AutoTrackWidth;
142 
143  wxFileName fn( GetCurrentFileName() );
144  fn.MakeRelativeTo( Prj().GetProjectPath() );
145  LoadWindowState( fn.GetFullPath() );
146 
147  return true;
148 }
149 
150 
152 {
153  wxFileName fn = Prj().GetProjectFullName();
154 
155  // Check for the filename before checking IsWritable as this
156  // will throw errors on bad names. Here, we just want to not
157  // save the Settings if we don't have a name
158  if( !fn.IsOk() )
159  return;
160 
161  if( !fn.IsDirWritable() )
162  return;
163 
165  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
166 
167  // TODO: Can this be pulled out of BASE_SCREEN?
168  project.m_BoardDrawingSheetFile = BASE_SCREEN::m_DrawingSheetFileName;
169 
170  project.m_LayerPresets = m_appearancePanel->GetUserLayerPresets();
171 
173 
174  // Save appearance control settings
175 
176  localSettings.m_ActiveLayer = GetActiveLayer();
178 
179  const PCB_DISPLAY_OPTIONS& displayOpts = GetDisplayOptions();
180 
181  localSettings.m_ContrastModeDisplay = displayOpts.m_ContrastModeDisplay;
182  localSettings.m_NetColorMode = displayOpts.m_NetColorMode;
183  localSettings.m_RatsnestMode = displayOpts.m_RatsnestMode;
184  localSettings.m_TrackOpacity = displayOpts.m_TrackOpacity;
185  localSettings.m_ViaOpacity = displayOpts.m_ViaOpacity;
186  localSettings.m_PadOpacity = displayOpts.m_PadOpacity;
187  localSettings.m_ZoneOpacity = displayOpts.m_ZoneOpacity;
188  localSettings.m_ZoneDisplayMode = displayOpts.m_ZoneDisplayMode;
189 
190  // Save Design settings
192  localSettings.m_AutoTrackWidth = bds.m_UseConnectedTrackWidth;
193 
194  // Save render settings that aren't stored in PCB_DISPLAY_OPTIONS
195 
196  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
197  GetCanvas()->GetView()->GetPainter()->GetSettings() );
198 
199  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
200 
201  localSettings.m_HiddenNets.clear();
202 
203  for( int netcode : rs->GetHiddenNets() )
204  {
205  if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
206  localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
207  }
208 
209  NET_SETTINGS& netSettings = project.NetSettings();
210 
211  netSettings.m_PcbNetColors.clear();
212 
213  for( const std::pair<const int, KIGFX::COLOR4D>& pair : rs->GetNetColorMap() )
214  {
215  if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
216  netSettings.m_PcbNetColors[net->GetNetname()] = pair.second;
217  }
218 
219  std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
220 
221  // NOTE: this assumes netclasses will have already been updated, which I think is the case
222  for( const std::pair<const wxString, NETCLASSPTR>& pair : netSettings.m_NetClasses )
223  {
224  if( netclassColors.count( pair.first ) )
225  pair.second->SetPcbColor( netclassColors.at( pair.first ) );
226  }
227 
229  SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
230 
231  localSettings.m_SelectionFilter = filterOpts;
232 
242  if( !Prj().IsNullProject() && fn.Exists() )
244 }
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:679
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
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...
PCB specific render settings.
Definition: pcb_painter.h:64
static const wxString ResolvePath(const wxString &aPath, const wxString &aProjectPath)
Resolve a path which might be project-relative or contain env variable references.
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:317
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:66
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
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.
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.