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-2020 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>
37 #include <pcbplot.h>
38 #include <pcb_painter.h>
39 #include <invoke_pcb_dialog.h>
41 #include <widgets/paged_dialog.h>
43 #include <project/net_settings.h>
44 #include <project/project_file.h>
46 
47 
48 
50  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
51 {
52  wxTreebook* book = aParent->GetTreebook();
53 
54  book->AddPage( new wxPanel( book ), _( "PCB Editor" ) );
55  book->AddSubPage( new PANEL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
56  book->AddSubPage( new PANEL_EDIT_OPTIONS( this, aParent ), _( "Editing Options" ) );
57  book->AddSubPage( new PANEL_PCBNEW_COLOR_SETTINGS( this, book ), _( "Colors" ) );
58 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
59  book->AddSubPage( new PANEL_PCBNEW_ACTION_PLUGINS( this, aParent ), _( "Action Plugins" ) );
60 #endif
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_PageLayoutDescrFileName = project.m_BoardPageLayoutDescrFile;
73 
74  // Load the drawing sheet description file, from the filename stored in
75  // BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
76  // If empty, or not existing, the default descr is loaded
78  Prj().GetProjectPath() );
79 
80  if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
81  {
82  ShowInfoBarError( _( "Error loading drawing sheet" ), true );
83  }
84 
85  // Load render settings that aren't stored in PCB_DISPLAY_OPTIONS
86 
87  NET_SETTINGS& netSettings = project.NetSettings();
88  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
89 
90  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
91  GetCanvas()->GetView()->GetPainter()->GetSettings() );
92 
93  std::set<int>& hiddenNets = rs->GetHiddenNets();
94  hiddenNets.clear();
95 
96  for( const wxString& hidden : localSettings.m_HiddenNets )
97  {
98  if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
99  hiddenNets.insert( net->GetNetCode() );
100  }
101 
102  std::map<int, KIGFX::COLOR4D>& netColors = rs->GetNetColorMap();
103  netColors.clear();
104 
105  for( const auto& pair : netSettings.m_PcbNetColors )
106  {
107  if( pair.second == COLOR4D::UNSPECIFIED )
108  continue;
109 
110  if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
111  netColors[ net->GetNetCode() ] = pair.second;
112  }
113 
114  std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
115  netclassColors.clear();
116 
117  for( const auto& pair : netSettings.m_NetClasses )
118  netclassColors[pair.first] = pair.second->GetPcbColor();
119 
120  m_appearancePanel->SetUserLayerPresets( project.m_LayerPresets );
121 
123  SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
124 
125  filterOpts = localSettings.m_SelectionFilter;
127 
129  opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay;
130  opts.m_NetColorMode = localSettings.m_NetColorMode;
131  opts.m_RatsnestMode = localSettings.m_RatsnestMode;
132  opts.m_TrackOpacity = localSettings.m_TrackOpacity;
133  opts.m_ViaOpacity = localSettings.m_ViaOpacity;
134  opts.m_PadOpacity = localSettings.m_PadOpacity;
135  opts.m_ZoneOpacity = localSettings.m_ZoneOpacity;
136  opts.m_ZoneDisplayMode = localSettings.m_ZoneDisplayMode;
137 
138  // No refresh here: callers of LoadProjectSettings refresh later
139  SetDisplayOptions( opts, false );
140 
142  bds.m_UseConnectedTrackWidth = localSettings.m_AutoTrackWidth;
143 
144  wxFileName fn( GetCurrentFileName() );
145  fn.MakeRelativeTo( Prj().GetProjectPath() );
146  LoadWindowState( fn.GetFullPath() );
147 
148  return true;
149 }
150 
151 
153 {
154  wxFileName fn = Prj().GetProjectFullName();
155 
156  // Check for the filename before checking IsWritable as this
157  // will throw errors on bad names. Here, we just want to not
158  // save the Settings if we don't have a name
159  if( !fn.IsOk() )
160  return;
161 
162  if( !fn.IsDirWritable() )
163  return;
164 
166  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
167 
168  // TODO: Can this be pulled out of BASE_SCREEN?
169  project.m_BoardPageLayoutDescrFile = BASE_SCREEN::m_PageLayoutDescrFileName;
170 
171  project.m_LayerPresets = m_appearancePanel->GetUserLayerPresets();
172 
174 
175  // Save appearance control settings
176 
177  localSettings.m_ActiveLayer = GetActiveLayer();
179 
180  const PCB_DISPLAY_OPTIONS& displayOpts = GetDisplayOptions();
181 
182  localSettings.m_ContrastModeDisplay = displayOpts.m_ContrastModeDisplay;
183  localSettings.m_NetColorMode = displayOpts.m_NetColorMode;
184  localSettings.m_RatsnestMode = displayOpts.m_RatsnestMode;
185  localSettings.m_TrackOpacity = displayOpts.m_TrackOpacity;
186  localSettings.m_ViaOpacity = displayOpts.m_ViaOpacity;
187  localSettings.m_PadOpacity = displayOpts.m_PadOpacity;
188  localSettings.m_ZoneOpacity = displayOpts.m_ZoneOpacity;
189  localSettings.m_ZoneDisplayMode = displayOpts.m_ZoneDisplayMode;
190 
191  // Save Design settings
193  localSettings.m_AutoTrackWidth = bds.m_UseConnectedTrackWidth;
194 
195  // Save render settings that aren't stored in PCB_DISPLAY_OPTIONS
196 
197  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
198  GetCanvas()->GetView()->GetPainter()->GetSettings() );
199 
200  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
201 
202  localSettings.m_HiddenNets.clear();
203 
204  for( int netcode : rs->GetHiddenNets() )
205  {
206  if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
207  localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
208  }
209 
210  NET_SETTINGS& netSettings = project.NetSettings();
211 
212  netSettings.m_PcbNetColors.clear();
213 
214  for( const std::pair<const int, KIGFX::COLOR4D>& pair : rs->GetNetColorMap() )
215  {
216  if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
217  netSettings.m_PcbNetColors[net->GetNetname()] = pair.second;
218  }
219 
220  std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
221 
222  // NOTE: this assumes netclasses will have already been updated, which I think is the case
223  for( const std::pair<const wxString, NETCLASSPTR>& pair : netSettings.m_NetClasses )
224  {
225  if( netclassColors.count( pair.first ) )
226  pair.second->SetPcbColor( netclassColors.at( pair.first ) );
227  }
228 
230  SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
231 
232  localSettings.m_SelectionFilter = filterOpts;
233 
243  if( !Prj().IsNullProject() && fn.Exists() )
245 }
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:51
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:754
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.
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
Definition: base_screen.h:89
wxTreebook * GetTreebook()
Definition: paged_dialog.h:52
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:39
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.
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:31
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:117
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
#define _(s)
Definition: 3d_actions.cpp:33
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:55
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.