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 
93  case ID_PCB_LIB_WIZARD:
95  {
96  bool tableChanged = false;
97  int r = 0;
98 
99  if( id == ID_PCB_LIB_TABLE_EDIT )
100  r = InvokePcbLibTableEditor( this, &GFootprintTable, Prj().PcbFootprintLibs() );
101  else
102  r = InvokeFootprintWizard( this, &GFootprintTable, Prj().PcbFootprintLibs() );
103 
104  if( r & 1 )
105  {
106  try
107  {
109 
110  GFootprintTable.Format( &sf, 0 );
111  tableChanged = true;
112  }
113  catch( const IO_ERROR& ioe )
114  {
115  wxString msg = wxString::Format( _(
116  "Error occurred saving the global footprint library "
117  "table:\n\n%s" ),
118  GetChars( ioe.What().GetData() )
119  );
120  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
121  }
122  }
123 
124  // If no board file is defined, do not save the project specific library table. It
125  // is kept in memory and created in the path when the new board is saved.
126  if( (r & 2) && !GetBoard()->GetFileName().IsEmpty() )
127  {
128  wxString tblName = Prj().FootprintLibTblName();
129 
130  try
131  {
132  Prj().PcbFootprintLibs()->Save( tblName );
133  tableChanged = true;
134  }
135  catch( const IO_ERROR& ioe )
136  {
137  wxString msg = wxString::Format( _(
138  "Error occurred saving project specific footprint library "
139  "table:\n\n%s" ),
140  GetChars( ioe.What() )
141  );
142  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
143  }
144  }
145 
146  FOOTPRINT_VIEWER_FRAME* viewer;
147 
148  if( tableChanged && (viewer = (FOOTPRINT_VIEWER_FRAME*)Kiway().Player( FRAME_PCB_MODULE_VIEWER, false )) != NULL )
149  {
150  viewer->ReCreateLibraryList();
151  }
152  }
153  break;
154 
156 #ifdef BUILD_GITHUB_PLUGIN
158 #endif
159  break;
160 
162  {
163  DIALOG_PADS_MASK_CLEARANCE dlg( this );
164 
165  if( dlg.ShowModal() == 1 && IsGalCanvasActive() )
166  {
167  for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
168  GetGalCanvas()->GetView()->Update( module );
169 
170  GetGalCanvas()->Refresh();
171  }
172  }
173  break;
174 
175  case wxID_PREFERENCES:
176  {
177  DIALOG_GENERALOPTIONS dlg( this );
178  dlg.ShowModal();
179  }
180  break;
181 
182  case ID_PCB_PAD_SETUP:
183  InstallPadOptionsFrame( NULL );
184  break;
185 
186  case ID_CONFIG_SAVE:
187  SaveProjectSettings( true );
188  break;
189 
190  case ID_CONFIG_READ:
191  {
192  fn = GetBoard()->GetFileName();
193  fn.SetExt( ProjectFileExtension );
194 
195  wxFileDialog dlg( this, _( "Read Project File" ), fn.GetPath(),
196  fn.GetFullName(), ProjectFileWildcard(),
197  wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
198 
199  if( dlg.ShowModal() == wxID_CANCEL )
200  break;
201 
202  if( !wxFileExists( dlg.GetPath() ) )
203  {
204  wxString msg = wxString::Format( _(
205  "File %s not found" ),
206  GetChars( dlg.GetPath() )
207  );
208  DisplayError( this, msg );
209  break;
210  }
211 
212  wxString pro_file = dlg.GetPath();
213 
214  Prj().ConfigLoad( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters(), pro_file );
215  }
216  break;
217 
218  // Hotkey IDs
221  break;
222 
225  break;
226 
229  break;
230 
232  // Display current hotkey list for Pcbnew.
234  break;
235 
236  default:
237  DisplayErrorMessage( this, "Unkown ID in Process Config",
238  wxString::Format( "PCB_EDIT_FRAME::Process_Config received ID %d", id ) );
239  break;
240  }
241 }
242 
243 
245 {
246  wxLogDebug( wxT( "Loading project '%s' settings." ),
247  GetChars( Prj().GetProjectFullName() ) );
248 
249  bool rc = Prj().ConfigLoad( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters() );
250 
251  // Load the page layout decr file, from the filename stored in
252  // BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
253  // If empty, or not existing, the default descr is loaded
255  wxString pg_fullfilename = WORKSHEET_LAYOUT::MakeFullFileName(
257  Prj().GetProjectPath() );
258 
259  pglayout.SetPageLayout( pg_fullfilename );
260 
261  return rc;
262 }
263 
264 
265 void PCB_EDIT_FRAME::SaveProjectSettings( bool aAskForSave )
266 {
267  wxFileName fn = Prj().GetProjectFullName();
268 
269  if( aAskForSave )
270  {
271  wxFileDialog dlg( this, _( "Save Project File" ),
272  fn.GetPath(), fn.GetFullName(),
273  ProjectFileWildcard(), wxFD_SAVE | wxFD_CHANGE_DIR );
274 
275  if( dlg.ShowModal() == wxID_CANCEL )
276  return;
277 
278  fn = dlg.GetPath();
279  }
280 
281  wxString pro_name = fn.GetFullPath();
282 
283  Prj().ConfigSave( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters(), pro_name );
284 }
285 
286 
288 {
289  PARAM_CFG_ARRAY pca;
290 
291  // This one cannot be cached because some settings are going to/from the BOARD,
292  // so pointers into that cannot be saved for long.
293 
294  pca.push_back( new PARAM_CFG_FILENAME( wxT( "PageLayoutDescrFile" ),
296 
297  pca.push_back( new PARAM_CFG_FILENAME( wxT( "LastNetListRead" ), &m_lastNetListRead ) );
298 
300 
301  return pca;
302 }
303 
304 
306 {
307  auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions();
308 
309  if( m_configParams.empty() )
310  {
311 
312  // Units used in dialogs and toolbars
313  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "Units" ),
314  (int*)&g_UserUnit, MILLIMETRES ) );
315 
316  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayPolarCoords" ),
317  &displ_opts->m_DisplayPolarCood, false ) );
318  // Display options and modes:
319  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "ShowNetNamesMode" ),
320  &displ_opts->m_DisplayNetNamesMode, 3, 0, 3 ) );
321  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayTrackFilled" ),
322  &displ_opts->m_DisplayPcbTrackFill, true ) );
323  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "TrackDisplayClearance" ),
324  (int*) &displ_opts->m_ShowTrackClearanceMode,
326  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadFill" ),
327  &displ_opts->m_DisplayPadFill, true ) );
328  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ViaFill" ),
329  &displ_opts->m_DisplayViaFill, true ) );
330  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadAffG" ),
331  &displ_opts->m_DisplayPadIsol, true ) );
332  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadSNum" ),
333  &displ_opts->m_DisplayPadNum, true ) );
334  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ModAffC" ),
335  &displ_opts->m_DisplayModEdgeFill, FILLED ) );
336  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ModAffT" ),
337  &displ_opts->m_DisplayModTextFill, FILLED ) );
338  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PcbAffT" ),
339  &displ_opts->m_DisplayDrawItemsFill, FILLED ) );
340  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "PcbShowZonesMode" ),
341  &displ_opts->m_DisplayZonesMode, 0, 0, 2 ) );
342 
343  // layer colors:
344 
345 
346  // Miscellaneous:
347  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "RotationAngle" ), &m_rotationAngle,
348  900, 1, 900 ) );
349  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "MaxLnkS" ),
350  &displ_opts->m_MaxLinksShowed,
351  3, 0, 15 ) );
352 
353 //FIXMEd
354 /* m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "TwoSegT" ),
355  &g_TwoSegmentTrackBuild, true ) );
356  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "SegmPcb45Only" )
357  , &g_Segments_45_Only, true ) );*/
358  }
359 
360  return m_configParams;
361 }
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:316
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:88
This file is part of the common library TODO brief description.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:339
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:342
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:120
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:94
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.
int InvokeFootprintWizard(wxTopLevelWindow *aParent, FP_LIB_TABLE *aGlobal, FP_LIB_TABLE *aProject)
Function InvokeFootprintWizard Runs the footprint library wizard for easy library addition...
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.
bool InvokeLayerSetup(wxTopLevelWindow *aCaller, BOARD *aBoard)
Function InvokeLayerSetup shows the layer setup dialog.
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: pcbnew.cpp:312
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:234
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:532
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:874
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:118
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:1382
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 bu 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:56
int m_rotationAngle
User defined rotation angle (in tenths of a degree).
wxString ProjectFileWildcard()
wxString m_lastNetListRead
Last net list read with relative path.
void InstallHotkeyFrame(EDA_BASE_FRAME *aParent, EDA_HOTKEY_CONFIG *aHotkeys)
Function InstallHotkeyFrame Create a hotkey editor dialog window with the provided hotkey configurati...
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:245
static const wxString MakeFullFileName(const wxString &aShortFileName, const wxString &aProjectPath)
Static function.
void ReCreateLibraryList()
Function ReCreateLibraryList.
The common library.
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:882
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:351
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:74
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
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...