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>
35 #include <tools/selection_tool.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 void PCB_EDIT_FRAME::On3DShapeLibWizard( wxCommandEvent& event )
49 {
50 #ifdef BUILD_GITHUB_PLUGIN
52 #endif
53 }
54 
55 
57  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
58 {
59  wxTreebook* book = aParent->GetTreebook();
60 
61  book->AddPage( new wxPanel( book ), _( "Pcbnew" ) );
62  book->AddSubPage( new PANEL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
63  book->AddSubPage( new PANEL_EDIT_OPTIONS( this, aParent ), _( "Editing Options" ) );
64  book->AddSubPage( new PANEL_PCBNEW_COLOR_SETTINGS( this, book ), _( "Colors" ) );
65 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
66  book->AddSubPage( new PANEL_PCBNEW_ACTION_PLUGINS( this, aParent ), _( "Action Plugins" ) );
67 #endif
68  book->AddSubPage( new PANEL_PCBNEW_DISPLAY_ORIGIN( this, aParent ), _( "Origins & Axes" ) );
69 
70  aHotkeysPanel->AddHotKeys( GetToolManager() );
71 }
72 
73 
75 {
76  PROJECT_FILE& project = Prj().GetProjectFile();
77  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
78 
80 
81  // Load the page layout decr file, from the filename stored in
82  // BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
83  // If empty, or not existing, the default descr is loaded
86  Prj().GetProjectPath() );
87 
88  pglayout.SetPageLayout( filename );
89 
90  // Load render settings that aren't stored in PCB_DISPLAY_OPTIONS
91 
92  NET_SETTINGS& netSettings = project.NetSettings();
93  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
94 
95  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
96  GetCanvas()->GetView()->GetPainter()->GetSettings() );
97 
98  std::set<int>& hiddenNets = rs->GetHiddenNets();
99  hiddenNets.clear();
100 
101  for( const wxString& hidden : localSettings.m_HiddenNets )
102  {
103  if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
104  hiddenNets.insert( net->GetNet() );
105  }
106 
107  std::map<int, KIGFX::COLOR4D>& netColors = rs->GetNetColorMap();
108  netColors.clear();
109 
110  for( const auto& pair : netSettings.m_PcbNetColors )
111  {
112  if( pair.second == COLOR4D::UNSPECIFIED )
113  continue;
114 
115  if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
116  netColors[net->GetNet()] = pair.second;
117  }
118 
119  std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
120  netclassColors.clear();
121 
122  for( const auto& pair : netSettings.m_NetClasses )
123  netclassColors[pair.first] = pair.second->GetPcbColor();
124 
126 
127  SELECTION_FILTER_OPTIONS& filterOpts = GetToolManager()->GetTool<SELECTION_TOOL>()->GetFilter();
128 
129  filterOpts = localSettings.m_SelectionFilter;
131 
133  opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay;
134  opts.m_NetColorMode = localSettings.m_NetColorMode;
135  opts.m_RatsnestMode = localSettings.m_RatsnestMode;
136  opts.m_TrackOpacity = localSettings.m_TrackOpacity;
137  opts.m_ViaOpacity = localSettings.m_ViaOpacity;
138  opts.m_PadOpacity = localSettings.m_PadOpacity;
139  opts.m_ZoneOpacity = localSettings.m_ZoneOpacity;
140  SetDisplayOptions( opts );
141 
142  wxFileName fn( GetCurrentFileName() );
143  fn.MakeRelativeTo( Prj().GetProjectPath() );
144  LoadWindowState( fn.GetFullPath() );
145 
146  return true;
147 }
148 
149 
151 {
152  wxFileName fn = Prj().GetProjectFullName();
153 
154  // Check for the filename before checking IsWritable as this
155  // will throw errors on bad names. Here, we just want to not
156  // save the Settings if we don't have a name
157  if( !fn.IsOk() )
158  return;
159 
160  if( !fn.IsDirWritable() )
161  return;
162 
163  PROJECT_FILE& project = Prj().GetProjectFile();
164  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
165 
166  // TODO: Can this be pulled out of BASE_SCREEN?
168 
170 
172 
173  // Save appearance control settings
174 
175  localSettings.m_ActiveLayer = GetActiveLayer();
177 
178  const PCB_DISPLAY_OPTIONS& displayOpts = GetDisplayOptions();
179 
180  localSettings.m_ContrastModeDisplay = displayOpts.m_ContrastModeDisplay;
181  localSettings.m_NetColorMode = displayOpts.m_NetColorMode;
182  localSettings.m_RatsnestMode = displayOpts.m_RatsnestMode;
183  localSettings.m_TrackOpacity = displayOpts.m_TrackOpacity;
184  localSettings.m_ViaOpacity = displayOpts.m_ViaOpacity;
185  localSettings.m_PadOpacity = displayOpts.m_PadOpacity;
186  localSettings.m_ZoneOpacity = displayOpts.m_ZoneOpacity;
187  localSettings.m_ZoneDisplayMode = displayOpts.m_ZoneDisplayMode;
188 
189  // Save render settings that aren't stored in PCB_DISPLAY_OPTIONS
190 
191  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
192  GetCanvas()->GetView()->GetPainter()->GetSettings() );
193 
194  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
195 
196  localSettings.m_HiddenNets.clear();
197 
198  for( int netcode : rs->GetHiddenNets() )
199  {
200  if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
201  localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
202  }
203 
204  NET_SETTINGS& netSettings = project.NetSettings();
205 
206  netSettings.m_PcbNetColors.clear();
207 
208  for( const std::pair<const int, KIGFX::COLOR4D>& pair : rs->GetNetColorMap() )
209  {
210  if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
211  netSettings.m_PcbNetColors[net->GetNetname()] = pair.second;
212  }
213 
214  std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
215 
216  // NOTE: this assumes netclasses will have already been updated, which I think is the case
217  for( const std::pair<const wxString, NETCLASSPTR>& pair : netSettings.m_NetClasses )
218  {
219  if( netclassColors.count( pair.first ) )
220  pair.second->SetPcbColor( netclassColors.at( pair.first ) );
221  }
222 
223  SELECTION_FILTER_OPTIONS& filterOpts = GetToolManager()->GetTool<SELECTION_TOOL>()->GetFilter();
224  localSettings.m_SelectionFilter = filterOpts;
225 
226  if( !Prj().IsNullProject() )
228 }
WS_DATA_MODEL handles the graphic items list to draw/plot the frame and title block.
Definition: ws_data_model.h:38
std::set< int > & GetHiddenNets()
Definition: pcb_painter.h:184
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.
VTBL_ENTRY PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:149
double m_TrackOpacity
Opacity override for all tracks.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
How zones are drawn (TODO: not yet used)
SELECTION_TOOL.
std::map< wxString, KIGFX::COLOR4D > & GetNetclassColorMap()
Definition: pcb_painter.h:180
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
void Invoke3DShapeLibsDownloaderWizard(wxWindow *aCaller)
Function Invoke3DShapeLibsDownloaderWizard Runs the downloader wizard for easy 3D shape libraries dow...
const NETINFO_LIST & GetNetInfo() const
Definition: class_board.h:724
void AddHotKeys(TOOL_MANAGER *aToolMgr)
void SetPageLayout(const wxString &aFullFileName=wxEmptyString, bool Append=false)
Populates the list with a custom layout, or the default layout, if no custom layout available.
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
Function GetDisplayOptions Display options control the way tracks, vias, outlines and other things ar...
void LoadWindowState(const wxString &aFileName)
PROJECT_FILE is the backing store for a PROJECT, in JSON format.
Definition: project_file.h:62
static WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
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:84
wxTreebook * GetTreebook()
Definition: paged_dialog.h:50
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:64
RATSNEST_MODE m_RatsnestMode
Ratsnest draw mode (all layers vs only visible layers)
PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
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)
NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:422
VTBL_ENTRY PROJECT_FILE & GetProjectFile() const
Definition: project.h:143
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void SaveProjectSettings() override
Function SaveProjectSettings saves changes to the project settings to the project (....
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.
This file contains data structures that are saved in the project file or project local settings file ...
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:115
double m_ZoneOpacity
Opacity override for filled zones.
void SetUserLayerPresets(std::vector< LAYER_PRESET > &aPresetList)
Updates the current layer presets from those saved in the project file
std::vector< LAYER_PRESET > GetUserLayerPresets() const
Returns a list of the layer presets created by the user
double m_ZoneOpacity
Opacity override for filled zone areas.
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
double m_PadOpacity
Opacity override for SMD pads and PTHs.
HIGH_CONTRAST_MODE m_ContrastModeDisplay
The current contrast mode.
static const wxString MakeFullFileName(const wxString &aShortFileName, const wxString &aProjectPath)
Static function.
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allows 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
bool SaveProject(const wxString &aFullPath=wxEmptyString)
Saves a loaded project.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
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.
void On3DShapeLibWizard(wxCommandEvent &event)
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
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:182
BOARD * GetBoard() const
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
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.