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 {
69  PROJECT_FILE& project = Prj().GetProjectFile();
70  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
71 
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 
81 
82  // Load render settings that aren't stored in PCB_DISPLAY_OPTIONS
83 
84  NET_SETTINGS& netSettings = project.NetSettings();
85  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
86 
87  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
88  GetCanvas()->GetView()->GetPainter()->GetSettings() );
89 
90  std::set<int>& hiddenNets = rs->GetHiddenNets();
91  hiddenNets.clear();
92 
93  for( const wxString& hidden : localSettings.m_HiddenNets )
94  {
95  if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
96  hiddenNets.insert( net->GetNetCode() );
97  }
98 
99  std::map<int, KIGFX::COLOR4D>& netColors = rs->GetNetColorMap();
100  netColors.clear();
101 
102  for( const auto& pair : netSettings.m_PcbNetColors )
103  {
104  if( pair.second == COLOR4D::UNSPECIFIED )
105  continue;
106 
107  if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
108  netColors[ net->GetNetCode() ] = pair.second;
109  }
110 
111  std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
112  netclassColors.clear();
113 
114  for( const auto& pair : netSettings.m_NetClasses )
115  netclassColors[pair.first] = pair.second->GetPcbColor();
116 
118 
120  SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
121 
122  filterOpts = localSettings.m_SelectionFilter;
124 
126  opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay;
127  opts.m_NetColorMode = localSettings.m_NetColorMode;
128  opts.m_RatsnestMode = localSettings.m_RatsnestMode;
129  opts.m_TrackOpacity = localSettings.m_TrackOpacity;
130  opts.m_ViaOpacity = localSettings.m_ViaOpacity;
131  opts.m_PadOpacity = localSettings.m_PadOpacity;
132  opts.m_ZoneOpacity = localSettings.m_ZoneOpacity;
133  opts.m_ZoneDisplayMode = localSettings.m_ZoneDisplayMode;
134  SetDisplayOptions( opts );
135 
137  bds.m_UseConnectedTrackWidth = localSettings.m_AutoTrackWidth;
138 
139  wxFileName fn( GetCurrentFileName() );
140  fn.MakeRelativeTo( Prj().GetProjectPath() );
141  LoadWindowState( fn.GetFullPath() );
142 
143  return true;
144 }
145 
146 
148 {
149  wxFileName fn = Prj().GetProjectFullName();
150 
151  // Check for the filename before checking IsWritable as this
152  // will throw errors on bad names. Here, we just want to not
153  // save the Settings if we don't have a name
154  if( !fn.IsOk() )
155  return;
156 
157  if( !fn.IsDirWritable() )
158  return;
159 
160  PROJECT_FILE& project = Prj().GetProjectFile();
161  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
162 
163  // TODO: Can this be pulled out of BASE_SCREEN?
165 
167 
169 
170  // Save appearance control settings
171 
172  localSettings.m_ActiveLayer = GetActiveLayer();
174 
175  const PCB_DISPLAY_OPTIONS& displayOpts = GetDisplayOptions();
176 
177  localSettings.m_ContrastModeDisplay = displayOpts.m_ContrastModeDisplay;
178  localSettings.m_NetColorMode = displayOpts.m_NetColorMode;
179  localSettings.m_RatsnestMode = displayOpts.m_RatsnestMode;
180  localSettings.m_TrackOpacity = displayOpts.m_TrackOpacity;
181  localSettings.m_ViaOpacity = displayOpts.m_ViaOpacity;
182  localSettings.m_PadOpacity = displayOpts.m_PadOpacity;
183  localSettings.m_ZoneOpacity = displayOpts.m_ZoneOpacity;
184  localSettings.m_ZoneDisplayMode = displayOpts.m_ZoneDisplayMode;
185 
186  // Save Design settings
188  localSettings.m_AutoTrackWidth = bds.m_UseConnectedTrackWidth;
189 
190  // Save render settings that aren't stored in PCB_DISPLAY_OPTIONS
191 
192  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
193  GetCanvas()->GetView()->GetPainter()->GetSettings() );
194 
195  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
196 
197  localSettings.m_HiddenNets.clear();
198 
199  for( int netcode : rs->GetHiddenNets() )
200  {
201  if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
202  localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
203  }
204 
205  NET_SETTINGS& netSettings = project.NetSettings();
206 
207  netSettings.m_PcbNetColors.clear();
208 
209  for( const std::pair<const int, KIGFX::COLOR4D>& pair : rs->GetNetColorMap() )
210  {
211  if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
212  netSettings.m_PcbNetColors[net->GetNetname()] = pair.second;
213  }
214 
215  std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
216 
217  // NOTE: this assumes netclasses will have already been updated, which I think is the case
218  for( const std::pair<const wxString, NETCLASSPTR>& pair : netSettings.m_NetClasses )
219  {
220  if( netclassColors.count( pair.first ) )
221  pair.second->SetPcbColor( netclassColors.at( pair.first ) );
222  }
223 
225  SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
226 
227  localSettings.m_SelectionFilter = filterOpts;
228 
238  if( !Prj().IsNullProject() && fn.Exists() )
240 }
std::set< int > & GetHiddenNets()
Definition: pcb_painter.h:187
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
void LoadDrawingSheet(const wxString &aFullFileName=wxEmptyString, bool Append=false)
Populates the list with a custom layout or the default layout if no custom layout is available.
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
AUI panel for controlling layer and object visibility and appearance.
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...
NET_SETTINGS & NetSettings()
Definition: project_file.h:92
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:745
void AddHotKeys(TOOL_MANAGER *aToolMgr)
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
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)
PROJECT_FILE is the backing store for a PROJECT, in JSON format.
Definition: project_file.h:62
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)
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_BoardPageLayoutDescrFile
PcbNew params.
Definition: project_file.h:157
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.
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
AUI panel for changing the selection tool filter controls.
#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.
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::vector< LAYER_PRESET > m_LayerPresets
List of stored layer presets.
Definition: project_file.h:178
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.