KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#include <pcb_edit_frame.h>
24#include <tool/tool_manager.h>
28#include <filename_resolver.h>
29#include <pcbplot.h>
30#include <pcb_painter.h>
31#include <pgm_base.h>
32#include <project.h>
38
39
41{
43
44 // Load the drawing sheet from the filename stored in the project
45 // If empty, or not existing, the default drawing sheet is loaded.
46 FILENAME_RESOLVER resolver;
47 resolver.SetProject( &Prj() );
48 resolver.SetProgramBase( &Pgm() );
49
50 wxString filename = resolver.ResolvePath( project.m_BoardDrawingSheetFile, Prj().GetProjectPath(),
51 { GetBoard()->GetEmbeddedFiles() } );
52
53 wxString msg;
54
55 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename, &msg ) )
56 ShowInfoBarError( msg, true );
57}
58
59
61{
63
64 BASE_SCREEN::m_DrawingSheetFileName = project.m_BoardDrawingSheetFile;
65
67 std::map<int, KIGFX::COLOR4D>& netColors = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs )->GetNetColorMap();
68 netColors.clear();
69
70 for( const auto& [netname, color] : project.NetSettings()->GetNetColorAssignments() )
71 {
72 if( color != COLOR4D::UNSPECIFIED )
73 {
74 if( NETINFO_ITEM* net = GetBoard()->GetNetInfo().GetNetItem( netname ) )
75 netColors[net->GetNetCode()] = color;
76 }
77 }
78
79 m_appearancePanel->SetUserLayerPresets( project.m_LayerPresets );
80 m_appearancePanel->SetUserViewports( project.m_Viewports );
81}
82
83
85{
86 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
87
89
90 // Load render settings that aren't stored in PCB_DISPLAY_OPTIONS
91
93 KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );
94
95 const NETINFO_LIST& nets = GetBoard()->GetNetInfo();
96
97 std::set<int>& hiddenNets = renderSettings->GetHiddenNets();
98 hiddenNets.clear();
99
100 for( const wxString& hidden : localSettings.m_HiddenNets )
101 {
102 if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
103 hiddenNets.insert( net->GetNetCode() );
104 }
105
106 for( NETINFO_ITEM* net : nets )
107 {
108 if( localSettings.m_HiddenNetclasses.count( net->GetNetClass()->GetName() ) )
109 hiddenNets.insert( net->GetNetCode() );
110 }
111
113 PCB_SELECTION_FILTER_OPTIONS& filterOpts = selTool->GetFilter();
114
115 filterOpts = localSettings.m_PcbSelectionFilter;
116 m_selectionFilterPanel->SetCheckboxesFromFilter( filterOpts );
117
119 opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay;
120 opts.m_NetColorMode = localSettings.m_NetColorMode;
121 opts.m_TrackOpacity = localSettings.m_TrackOpacity;
122 opts.m_ViaOpacity = localSettings.m_ViaOpacity;
123 opts.m_PadOpacity = localSettings.m_PadOpacity;
124 opts.m_ZoneOpacity = localSettings.m_ZoneOpacity;
125 opts.m_ZoneDisplayMode = localSettings.m_ZoneDisplayMode;
126 opts.m_ImageOpacity = localSettings.m_ImageOpacity;
127 opts.m_FilledShapeOpacity = localSettings.m_ShapeOpacity;
128 opts.m_OutsideGroupOpacity = localSettings.m_OutsideGroupOpacity;
129
130 // No refresh here: callers of LoadProjectSettings refresh later
131 SetDisplayOptions( opts, false );
132
134
135 wxFileName fn( GetCurrentFileName() );
136 fn.MakeRelativeTo( Prj().GetProjectPath() );
137 LoadWindowState( fn.GetFullPath() );
138
139 return true;
140}
141
142
144{
145 wxFileName fn = Prj().GetProjectFullName();
146
147 // Check for the filename before checking IsWritable as this
148 // will throw errors on bad names. Here, we just want to not
149 // save the Settings if we don't have a name
150 if( !fn.IsOk() )
151 return;
152
153 if( !fn.IsDirWritable() )
154 return;
155
157
158 // save some local settings like appearance control settings
160
161 // TODO: Can this be pulled out of BASE_SCREEN?
162 project.m_BoardDrawingSheetFile = BASE_SCREEN::m_DrawingSheetFileName;
163
164 project.m_LayerPresets = m_appearancePanel->GetUserLayerPresets();
165 project.m_Viewports = m_appearancePanel->GetUserViewports();
166
168
169 // Save render settings that aren't stored in PCB_DISPLAY_OPTIONS
170
171 std::shared_ptr<NET_SETTINGS>& netSettings = project.NetSettings();
172 const NETINFO_LIST& nets = GetBoard()->GetNetInfo();
174 KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );
175
176 netSettings->ClearNetColorAssignments();
177
178 for( const auto& [ netcode, color ] : renderSettings->GetNetColorMap() )
179 {
180 if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
181 netSettings->SetNetColorAssignment( net->GetNetname(), color );
182 }
183
193 if( !Prj().IsNullProject() && fn.Exists() )
195}
196
197
199{
200 wxFileName fn = Prj().GetProjectFullName();
201
202 // Check for the filename before checking IsWritable as this
203 // will throw errors on bad names. Here, we just want to not
204 // save the Settings if we don't have a name
205 if( !fn.IsOk() )
206 return;
207
208 if( !fn.IsDirWritable() )
209 return;
210
211 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
212
213 // Save appearance control settings
214 localSettings.m_ActiveLayer = GetActiveLayer();
215 localSettings.m_ActiveLayerPreset = m_appearancePanel->GetActiveLayerPreset();
216
217 const PCB_DISPLAY_OPTIONS& displayOpts = GetDisplayOptions();
218
219 localSettings.m_ContrastModeDisplay = displayOpts.m_ContrastModeDisplay;
220 localSettings.m_NetColorMode = displayOpts.m_NetColorMode;
221 localSettings.m_TrackOpacity = displayOpts.m_TrackOpacity;
222 localSettings.m_ViaOpacity = displayOpts.m_ViaOpacity;
223 localSettings.m_PadOpacity = displayOpts.m_PadOpacity;
224 localSettings.m_ZoneOpacity = displayOpts.m_ZoneOpacity;
225 localSettings.m_ZoneDisplayMode = displayOpts.m_ZoneDisplayMode;
226 localSettings.m_ImageOpacity = displayOpts.m_ImageOpacity;
227 localSettings.m_ShapeOpacity = displayOpts.m_FilledShapeOpacity;
228 localSettings.m_OutsideGroupOpacity = displayOpts.m_OutsideGroupOpacity;
229
230 // Save Design settings
232
233 // Net display settings
234 const NETINFO_LIST& nets = GetBoard()->GetNetInfo();
236 KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );
237
238 localSettings.m_HiddenNets.clear();
239
240 for( int netcode : renderSettings->GetHiddenNets() )
241 {
242 if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
243 localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
244 }
245
246 if( TOOL_MANAGER* toolMgr = GetToolManager() )
247 {
248 if( PCB_SELECTION_TOOL* selTool = toolMgr->GetTool<PCB_SELECTION_TOOL>() )
249 localSettings.m_PcbSelectionFilter = selTool->GetFilter();
250 }
251}
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition base_screen.h:81
const NETINFO_LIST & GetNetInfo() const
Definition board.h:1241
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition board.cpp:3709
void RecordDRCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition board.cpp:569
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
static DS_DATA_MODEL & GetTheInstance()
Return the instance of DS_DATA_MODEL used in the application.
void LoadWindowState(const wxString &aFileName)
SETTINGS_MANAGER * GetSettingsManager() const
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, INFOBAR_MESSAGE_TYPE aType=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...
Provide an extensible class to resolve 3D model paths.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack)
Determine the full path of the given file name.
void SetProgramBase(PGM_BASE *aBase)
Set a pointer to the application's PGM_BASE instance used to extract the local env vars.
bool SetProject(const PROJECT *aProject, bool *flgChanged=nullptr)
Set the current KiCad project directory as the first entry in the model path list.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Definition pcb_painter.h:94
std::set< int > & GetHiddenNets()
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
PAINTER * GetPainter() const
Return the painter object used by the view for drawing VIEW_ITEM objects.
Definition view.h:242
Handle the data for a net.
Definition netinfo.h:50
Container for NETINFO_ITEM elements, which are the nets.
Definition netinfo.h:232
NETINFO_ITEM * GetNetItem(int aNetCode) const
APPEARANCE_CONTROLS * m_appearancePanel
PANEL_SELECTION_FILTER * m_selectionFilterPanel
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual PCB_LAYER_ID GetActiveLayer() const
BOARD * GetBoard() const
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Return the BOARD_DESIGN_SETTINGS for the open project.
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aRefresh=true)
Update the current display options.
double m_TrackOpacity
Opacity override for all tracks.
double m_FilledShapeOpacity
Opacity override for graphic shapes.
double m_ZoneOpacity
Opacity override for filled zone areas.
double m_OutsideGroupOpacity
Opacity override for items outside the entered group.
double m_ImageOpacity
Opacity override for user images.
double m_PadOpacity
Opacity override for SMD pads and PTHs.
double m_ViaOpacity
Opacity override for all types of via.
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
NET_COLOR_MODE m_NetColorMode
How to use color overrides on specific nets and netclasses.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the KIGFX::VIEW instance used in the panel.
void LoadDrawingSheet()
Load the drawing sheet file.
void ApplyProjectFileSettings()
Apply what the project file sets and this frame caches, leaving the local settings alone.
void SaveProjectLocalSettings() override
Save changes to the project local settings.
bool LoadProjectSettings()
Load the current project's file configuration settings which are pertinent to this PCB_EDIT_FRAME ins...
wxString GetCurrentFileName() const override
Get the full filename + path of the currently opened file in the frame.
void saveProjectSettings() override
Save any design-related project settings associated with this frame.
The selection tool: currently supports:
PCB_SELECTION_FILTER_OPTIONS & GetFilter()
The backing store for a PROJECT, in JSON format.
The project local settings are things that are attached to a particular project, but also might be pa...
double m_PadOpacity
Opacity override for SMD pads and PTH.
double m_ViaOpacity
Opacity override for all types of via.
PCB_SELECTION_FILTER_OPTIONS m_PcbSelectionFilter
State of the selection filter widgets.
wxString m_ActiveLayerPreset
The name of a LAYER_PRESET that is currently activated (or blank if none)
double m_TrackOpacity
Opacity override for all tracks.
double m_ZoneOpacity
Opacity override for filled zones.
bool m_AutoTrackWidth
The current setting for whether to automatically adjust track widths to match.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
How zones are drawn.
double m_ShapeOpacity
Opacity override for graphic shapes.
double m_OutsideGroupOpacity
Opacity override for items outside the entered group.
PCB_LAYER_ID m_ActiveLayer
The current (active) board layer for editing.
HIGH_CONTRAST_MODE m_ContrastModeDisplay
The current contrast mode.
NET_COLOR_MODE m_NetColorMode
The current net color mode.
std::vector< wxString > m_HiddenNets
A list of netnames that have been manually hidden in the board editor.
std::set< wxString > m_HiddenNetclasses
double m_ImageOpacity
Opacity override for user images.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition project.cpp:271
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition project.h:207
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:201
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Master controller class:
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
PROJECT & Prj()
Definition kicad.cpp:730
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
This file contains data structures that are saved in the project file or project local settings file ...