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-2019 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 <fctsys.h>
28 #include <kiface_i.h>
29 #include <confirm.h>
30 #include <gestfich.h>
31 #include <macros.h>
32 #include <pcb_edit_frame.h>
33 #include <board_design_settings.h>
34 #include <plotter.h>
35 #include <panel_hotkeys_editor.h>
36 #include <panel_edit_options.h>
38 #include <panel_display_options.h>
40 #include <tool/tool_manager.h>
41 #include <tools/selection_tool.h>
42 #include <fp_lib_table.h>
43 #include <ws_data_model.h>
44 #include <class_board.h>
45 #include <class_module.h>
46 #include <pcbplot.h>
47 #include <pcb_painter.h>
48 #include <footprint_viewer_frame.h>
49 #include <invoke_pcb_dialog.h>
51 #include <widgets/paged_dialog.h>
53 #include <project/net_settings.h>
54 #include <project/project_file.h>
56 
57 
58 void PCB_EDIT_FRAME::On3DShapeLibWizard( wxCommandEvent& event )
59 {
60 #ifdef BUILD_GITHUB_PLUGIN
62 #endif
63 }
64 
65 
67  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
68 {
69  PAGED_TREEBOOK* book = aParent->GetTreebook();
70 
71  book->AddGroupEntry( _( "Pcbnew" ) );
72  book->AddSubPage( new PANEL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
73  book->AddSubPage( new PANEL_PCBNEW_COLOR_SETTINGS( this, book ), _( "Colors" ) );
74  book->AddSubPage( new PANEL_EDIT_OPTIONS( this, aParent ), _( "Editing Options" ) );
75 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
76  book->AddSubPage( new PANEL_PCBNEW_ACTION_PLUGINS( this, aParent ), _( "Action Plugins" ) );
77 #endif
78 
79  aHotkeysPanel->AddHotKeys( GetToolManager() );
80 }
81 
82 
84 {
85  wxLogDebug( wxT( "Loading project '%s' settings." ), GetChars( Prj().GetProjectFullName() ) );
86 
87  PROJECT_FILE& project = Prj().GetProjectFile();
88  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
89 
91 
92  // Load the page layout decr file, from the filename stored in
93  // BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
94  // If empty, or not existing, the default descr is loaded
97  Prj().GetProjectPath() );
98 
99  pglayout.SetPageLayout( filename );
100 
101  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
102  GetCanvas()->GetView()->GetPainter()->GetSettings() );
103 
104  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
105  std::set<int> hiddenNets;
106 
107  for( const wxString& hidden : localSettings.m_HiddenNets )
108  {
109  if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
110  hiddenNets.insert( net->GetNet() );
111  }
112 
113  rs->LoadNetSettings( project.NetSettings(), nets, hiddenNets );
114 
115  SELECTION_FILTER_OPTIONS& filterOpts = GetToolManager()->GetTool<SELECTION_TOOL>()->GetFilter();
116 
117  filterOpts = localSettings.m_SelectionFilter;
119 
121  opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay;
122  SetDisplayOptions( opts );
123 
124  SetActiveLayer( localSettings.m_ActiveLayer );
125 
126  return true;
127 }
128 
129 
131 {
132  wxFileName fn = Prj().GetProjectFullName();
133 
134  // Check for the filename before checking IsWritable as this
135  // will throw errors on bad names. Here, we just want to not
136  // save the Settings if we don't have a name
137  if( !fn.IsOk() )
138  return;
139 
140  if( !fn.IsDirWritable() )
141  return;
142 
143  PROJECT_FILE& project = Prj().GetProjectFile();
144  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
145 
146  // TODO: Can this be pulled out of BASE_SCREEN?
148 
150 
151  localSettings.m_ActiveLayer = GetActiveLayer();
152 
154 
155  KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
156  GetCanvas()->GetView()->GetPainter()->GetSettings() );
157 
158  NETINFO_LIST& nets = GetBoard()->GetNetInfo();
159 
160  localSettings.m_HiddenNets.clear();
161 
162  for( int netcode : rs->GetHiddenNets() )
163  {
164  if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
165  localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
166  }
167 
168  SELECTION_FILTER_OPTIONS& filterOpts = GetToolManager()->GetTool<SELECTION_TOOL>()->GetFilter();
169  localSettings.m_SelectionFilter = filterOpts;
170 
172 }
WS_DATA_MODEL handles the graphic items list to draw/plot the frame and title block.
Definition: ws_data_model.h:39
std::set< int > & GetHiddenNets()
Definition: pcb_painter.h:205
bool AddGroupEntry(const wxString &text, int imageId=NO_IMAGE)
This file is part of the common library TODO brief description.
SETTINGS_MANAGER * GetSettingsManager() const
This file is part of the common library.
VTBL_ENTRY PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:143
SELECTION_TOOL.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
The project local settings are things that are attached to a particular project, but also might be pa...
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:741
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)
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...
PROJECT_FILE is the backing store for a PROJECT, in JSON format.
Definition: project_file.h:62
This file contains miscellaneous commonly used macros and functions.
static WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
Board plot function definition file.
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
Definition: base_screen.h:57
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:63
PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
void SetCheckboxesFromFilter(SELECTION_FILTER_OPTIONS &aOptions)
wxString m_BoardPageLayoutDescrFile
PcbNew params.
Definition: project_file.h:168
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:137
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void LoadNetSettings(const NET_SETTINGS &aSettings, const NETINFO_LIST &aList, const std::set< int > &aHiddenNets)
Loads net-specific render settings.
void SaveProjectSettings() override
Function SaveProjectSettings saves changes to the project settings to the project (....
Definition of file extensions used in Kicad.
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:117
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
HIGH_CONTRAST_MODE m_ContrastModeDisplay
The current contrast mode.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
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
PAGED_TREEBOOK * GetTreebook()
Definition: paged_dialog.h:61
bool SaveProject(const wxString &aFullPath=wxEmptyString)
Saves a loaded project.
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:74
BOARD * GetBoard() const
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
void SetActiveLayer(PCB_LAYER_ID aLayer) override
Function SetActiveLayer will change the currently active layer to aLayer and also update the PCB_LAYE...