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-2017 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 
31 #include <fctsys.h>
32 #include <kiface_i.h>
33 #include <project.h>
34 #include <class_drawpanel.h>
35 #include <pcb_draw_panel_gal.h>
36 #include <confirm.h>
37 #include <gestfich.h>
38 #include <xnode.h>
39 #include <common.h>
40 #include <macros.h>
41 #include <pcb_edit_frame.h>
42 #include <board_design_settings.h>
43 #include <plotter.h>
44 #include <worksheet.h>
45 #include <dialog_hotkeys_editor.h>
46 #include <fp_lib_table.h>
48 
49 #include <class_board.h>
50 #include <class_module.h>
51 #include <pcbplot.h>
52 #include <pcbnew.h>
53 #include <pcbnew_id.h>
54 #include <hotkeys.h>
55 #include <footprint_viewer_frame.h>
56 
57 #include <invoke_pcb_dialog.h>
58 #include <dialog_mask_clearance.h>
59 #include <dialog_general_options.h>
61 #include <view/view.h>
62 
63 
64 void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
65 {
66  int id = event.GetId();
67  wxFileName fn;
68 
69  switch( id )
70  {
72  if( InvokeLayerSetup( this, GetBoard() ) )
73  {
74  PCB_LAYER_ID cur_layer = GetActiveLayer();
75 
76  // If after showing the dialog the user has removed the active layer,
77  // then select a new active layer (front copper layer).
78  if( !GetBoard()->GetEnabledLayers()[ cur_layer ] )
79  cur_layer = F_Cu;
80 
81  SetActiveLayer( cur_layer );
82  OnModify();
85 
86  if( IsGalCanvasActive() )
87  static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->SyncLayersVisibility( GetBoard() );
88 
89  GetCanvas()->Refresh();
90  }
91  break;
92 
94  {
95  bool tableChanged = false;
96  int r = InvokePcbLibTableEditor( this, &GFootprintTable, Prj().PcbFootprintLibs() );
97 
98  if( r & 1 )
99  {
100  try
101  {
103 
104  GFootprintTable.Format( &sf, 0 );
105  tableChanged = true;
106  }
107  catch( const IO_ERROR& ioe )
108  {
109  wxString msg = wxString::Format( _(
110  "Error occurred saving the global footprint library "
111  "table:\n\n%s" ),
112  GetChars( ioe.What().GetData() )
113  );
114  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
115  }
116  }
117 
118  // If no board file is defined, do not save the project specific library table. It
119  // is kept in memory and created in the path when the new board is saved.
120  if( (r & 2) && !GetBoard()->GetFileName().IsEmpty() )
121  {
122  wxString tblName = Prj().FootprintLibTblName();
123 
124  try
125  {
126  Prj().PcbFootprintLibs()->Save( tblName );
127  tableChanged = true;
128  }
129  catch( const IO_ERROR& ioe )
130  {
131  wxString msg = wxString::Format( _(
132  "Error occurred saving project specific footprint library "
133  "table:\n\n%s" ),
134  GetChars( ioe.What() )
135  );
136  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
137  }
138  }
139 
140  FOOTPRINT_VIEWER_FRAME* viewer;
141 
142  if( tableChanged && (viewer = (FOOTPRINT_VIEWER_FRAME*)Kiway().Player( FRAME_PCB_MODULE_VIEWER, false )) != NULL )
143  {
144  viewer->ReCreateLibraryList();
145  }
146  }
147  break;
148 
150 #ifdef BUILD_GITHUB_PLUGIN
152 #endif
153  break;
154 
156  {
157  DIALOG_PADS_MASK_CLEARANCE dlg( this );
158 
159  if( dlg.ShowModal() == 1 && IsGalCanvasActive() )
160  {
161  for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
162  GetGalCanvas()->GetView()->Update( module );
163 
164  GetGalCanvas()->Refresh();
165  }
166  }
167  break;
168 
169  case wxID_PREFERENCES:
170  {
171  DIALOG_GENERALOPTIONS dlg( this );
172  dlg.ShowModal();
173  }
174  break;
175 
176  case ID_PCB_PAD_SETUP:
177  InstallPadOptionsFrame( NULL );
178  break;
179 
180  case ID_CONFIG_SAVE:
181  SaveProjectSettings( true );
182  break;
183 
184  case ID_CONFIG_READ:
185  {
186  fn = GetBoard()->GetFileName();
187  fn.SetExt( ProjectFileExtension );
188 
189  wxFileDialog dlg( this, _( "Load Project File" ), fn.GetPath(),
190  fn.GetFullName(), ProjectFileWildcard(),
191  wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
192 
193  if( dlg.ShowModal() == wxID_CANCEL )
194  break;
195 
196  if( !wxFileExists( dlg.GetPath() ) )
197  {
198  wxString msg = wxString::Format( _(
199  "File %s not found" ),
200  GetChars( dlg.GetPath() )
201  );
202  DisplayError( this, msg );
203  break;
204  }
205 
206  wxString pro_file = dlg.GetPath();
207 
208  Prj().ConfigLoad( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters(), pro_file );
209  }
210  break;
211 
212  // Hotkey IDs
215  break;
216 
219  break;
220 
223  break;
224 
226  // Display current hotkey list for Pcbnew.
228  break;
229 
230  default:
231  DisplayErrorMessage( this, "Unknown ID in Process Config",
232  wxString::Format( "PCB_EDIT_FRAME::Process_Config received ID %d", id ) );
233  break;
234  }
235 }
236 
237 
239 {
240  wxLogDebug( wxT( "Loading project '%s' settings." ),
241  GetChars( Prj().GetProjectFullName() ) );
242 
243  bool rc = Prj().ConfigLoad( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters() );
244 
245  // Load the page layout decr file, from the filename stored in
246  // BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
247  // If empty, or not existing, the default descr is loaded
249  wxString pg_fullfilename = WORKSHEET_LAYOUT::MakeFullFileName(
251  Prj().GetProjectPath() );
252 
253  pglayout.SetPageLayout( pg_fullfilename );
254 
255  return rc;
256 }
257 
258 
259 void PCB_EDIT_FRAME::SaveProjectSettings( bool aAskForSave )
260 {
261  wxFileName fn = Prj().GetProjectFullName();
262 
263  if( aAskForSave )
264  {
265  wxFileDialog dlg( this, _( "Save Project File" ),
266  fn.GetPath(), fn.GetFullName(),
267  ProjectFileWildcard(), wxFD_SAVE | wxFD_CHANGE_DIR );
268 
269  if( dlg.ShowModal() == wxID_CANCEL )
270  return;
271 
272  fn = dlg.GetPath();
273  }
274 
275  wxString pro_name = fn.GetFullPath();
276 
277  Prj().ConfigSave( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters(), pro_name );
278 }
279 
280 
282 {
283  PARAM_CFG_ARRAY pca;
284 
285  // This one cannot be cached because some settings are going to/from the BOARD,
286  // so pointers into that cannot be saved for long.
287 
288  pca.push_back( new PARAM_CFG_FILENAME( wxT( "PageLayoutDescrFile" ),
290 
291  pca.push_back( new PARAM_CFG_FILENAME( wxT( "LastNetListRead" ), &m_lastNetListRead ) );
292 
294 
295  return pca;
296 }
297 
298 
300 {
301  auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions();
302 
303  if( m_configParams.empty() )
304  {
305 
306  // Units used in dialogs and toolbars
307  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "Units" ),
308  (int*)&g_UserUnit, MILLIMETRES ) );
309 
310  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayPolarCoords" ),
311  &displ_opts->m_DisplayPolarCood, false ) );
312  // Display options and modes:
313  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "ShowNetNamesMode" ),
314  &displ_opts->m_DisplayNetNamesMode, 3, 0, 3 ) );
315  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayTrackFilled" ),
316  &displ_opts->m_DisplayPcbTrackFill, true ) );
317  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "TrackDisplayClearance" ),
318  (int*) &displ_opts->m_ShowTrackClearanceMode,
320  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadFill" ),
321  &displ_opts->m_DisplayPadFill, true ) );
322  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ViaFill" ),
323  &displ_opts->m_DisplayViaFill, true ) );
324  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadAffG" ),
325  &displ_opts->m_DisplayPadIsol, true ) );
326  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadSNum" ),
327  &displ_opts->m_DisplayPadNum, true ) );
328  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ModAffC" ),
329  &displ_opts->m_DisplayModEdgeFill, FILLED ) );
330  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ModAffT" ),
331  &displ_opts->m_DisplayModTextFill, FILLED ) );
332  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PcbAffT" ),
333  &displ_opts->m_DisplayDrawItemsFill, FILLED ) );
334  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "PcbShowZonesMode" ),
335  &displ_opts->m_DisplayZonesMode, 0, 0, 2 ) );
336 
337  // layer colors:
338 
339 
340  // Miscellaneous:
341  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "RotationAngle" ), &m_rotationAngle,
342  900, 1, 900 ) );
343  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "MaxLnkS" ),
344  &displ_opts->m_MaxLinksShowed,
345  3, 0, 15 ) );
346 
347 //FIXMEd
348 /* m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "TwoSegT" ),
349  &g_TwoSegmentTrackBuild, true ) );
350  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "SegmPcb45Only" )
351  , &g_Segments_45_Only, true ) );*/
352  }
353 
354  return m_configParams;
355 }
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
A list of parameters type.
VTBL_ENTRY void ConfigSave(const SEARCH_STACK &aSList, const wxString &aGroupName, const PARAM_CFG_ARRAY &aParams, const wxString &aFileName=wxEmptyString)
Function ConfigSave saves the current "project" parameters into the wxConfigBase* derivative...
Definition: project.cpp:318
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
PARAM_CFG_ARRAY GetProjectFileParameters()
Function GetProjectFileParameters returns a project file parameter list for Pcbnew.
void Process_Config(wxCommandEvent &event)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:199
This file is part of the common library TODO brief description.
bool InvokeLayerSetup(PCB_EDIT_FRAME *aCaller, BOARD *aBoard)
Function InvokeLayerSetup shows the layer setup dialog.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:338
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:359
const wxString ProjectFileExtension
Class BOARD to handle a board.
void ExportHotkeyConfigToFile(EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
Function ExportHotkeyConfigToFile Prompt the user for an old hotkey file to read, and read it...
Component library viewer main window.
MODULE * Next() const
Definition: class_module.h:121
bool LoadProjectSettings()
Load the current project&#39;s file configuration settings which are pertinent to this PCB_EDIT_FRAME ins...
void ReCreateLayerBox(bool aForceResizeToolbar=true)
Re create the layer Box by clearing the old list, and building le new one, from the new layers names ...
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96
BOARD * GetBoard() const
PARAM_CFG_ARRAY & GetConfigurationSettings()
Function GetConfigurationSettings returns the Pcbnew applications settings list.
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
struct EDA_HOTKEY_CONFIG g_Pcbnew_Editor_Hotkeys_Descr[]
void SaveProjectSettings(bool aAskForSave) override
Function SaveProjectSettings saves changes to the project settings to the project (...
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
Configuration parameter - PARAM_CFG_FILENAME Class Same as PARAM_CFG_WXSTRING, but stores "\" as "/"...
static WORKSHEET_LAYOUT & GetTheInstance()
static function: returns the instance of WORKSHEET_LAYOUT used in the application ...
void * GetDisplayOptions() override
Function GetDisplayOptions returns the display options current in use Display options are relative to...
Pcbnew hotkeys.
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: pcbnew.cpp:311
This file contains miscellaneous commonly used macros and functions.
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:180
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void DisplayHotkeyList(EDA_BASE_FRAME *aFrame, struct EDA_HOTKEY_CONFIG *aDescList)
Function DisplayHotkeyList Displays the current hotkey list.
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
PCB_LAYER_ID
A quick note on layer IDs:
const wxString & GetFileName() const
Definition: class_board.h:236
Configuration parameter - Integer Class.
int InvokePcbLibTableEditor(wxTopLevelWindow *aCaller, FP_LIB_TABLE *aGlobal, FP_LIB_TABLE *aProject)
Function InvokePcbLibTableEditor shows the modal DIALOG_FP_LIB_TABLE for purposes of editing two lib ...
The common library.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:535
struct EDA_HOTKEY_CONFIG g_Board_Editor_Hotkeys_Descr[]
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:895
Configuration parameter - Boolean Class.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
VTBL_ENTRY const wxString FootprintLibTblName() const
Function FootprintLibTblName returns the path and filename of this project&#39;s fp-lib-table, i.e.
Definition: project.cpp:120
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1499
void Invoke3DShapeLibsDownloaderWizard(wxTopLevelWindow *aCaller)
Function Invoke3DShapeLibsDownloaderWizard Runs the downloader wizard for easy 3D shape libraries dow...
void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
WORKSHEET_LAYOUT handles the graphic items list to draw/plot the title block and other items (page re...
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:57
int m_rotationAngle
User defined rotation angle (in tenths of a degree).
wxString ProjectFileWildcard()
wxString m_lastNetListRead
Last net list read with relative path.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
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:92
DIALOG_PADS_MASK_CLEARANCE, derived from DIALOG_PADS_MASK_CLEARANCE_BASE.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
DLIST< MODULE > m_Modules
Definition: class_board.h:247
static const wxString MakeFullFileName(const wxString &aShortFileName, const wxString &aProjectPath)
Static function.
void ReCreateLibraryList()
Function ReCreateLibraryList.
The common library.
void InstallHotkeyFrame(EDA_BASE_FRAME *aParent, EDA_HOTKEY_CONFIG *aHotkeys, EDA_HOTKEY_CONFIG *aShowHotkeys)
Function InstallHotkeyFrame Create a hotkey editor dialog window with the provided hotkey configurati...
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:903
classes and function to generate graphics to plt or draw titles blocks and frame references ...
void InstallPadOptionsFrame(D_PAD *pad)
void AppendConfigs(PARAM_CFG_ARRAY *aResult)
Function AppendConfigs appends to aResult the configuration setting accessors which will later allow ...
PARAM_CFG_ARRAY m_configParams
List of Pcbnew configuration settings.
VTBL_ENTRY bool ConfigLoad(const SEARCH_STACK &aSearchS, const wxString &aGroupName, const PARAM_CFG_ARRAY &aParams, const wxString &aForeignConfigFileName=wxEmptyString)
Function ConfigLoad reads a subset of parameters from the "project" file.
Definition: project.cpp:353
Module description (excepted pads)
void ReFillLayerWidget()
Function ReFillLayerWidget changes out all the layers in m_Layers and may be called upon loading a ne...
void ImportHotkeyConfigFromFile(EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
Function ImportHotkeyConfigFromFile Prompt the user for an old hotkey file to read, and read it.
#define GROUP_PCB
Names of sub sections where to store project info in *.pro project config files.
Definition: config_params.h:43
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:185
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
virtual void SetActiveLayer(PCB_LAYER_ID aLayer) override
Function SetActiveLayer will change the currently active layer to aLayer and also update the PCB_LAYE...
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.
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...