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-2016 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2016 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 <wxPcbStruct.h>
43 #include <plot_common.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 <module_editor_frame.h>
56 #include <modview_frame.h>
57 
58 #include <invoke_pcb_dialog.h>
59 #include <dialog_mask_clearance.h>
60 #include <dialog_general_options.h>
62 #include <view/view.h>
63 
64 
65 void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
66 {
67  int id = event.GetId();
68  wxFileName fn;
69 
70  switch( id )
71  {
74  m_auimgr.GetPane( wxT( "m_LayersManagerToolBar" ) ).Show( m_show_layer_manager_tools );
75  m_auimgr.Update();
76 
77  GetMenuBar()->SetLabel( ID_MENU_PCB_SHOW_HIDE_LAYERS_MANAGER,
79  _("Hide &Layers Manager" ) : _("Show &Layers Manager" ));
80  break;
81 
84  m_auimgr.GetPane( wxT( "m_microWaveToolBar" ) ).Show( m_show_microwave_tools );
85  m_auimgr.Update();
86 
87  GetMenuBar()->SetLabel( ID_MENU_PCB_SHOW_HIDE_MUWAVE_TOOLBAR,
89  _( "Hide Microwa&ve Toolbar" ): _( "Show Microwa&ve Toolbar" ));
90  break;
91 
92 
94  if( InvokeLayerSetup( this, GetBoard() ) )
95  {
96  PCB_LAYER_ID cur_layer = GetActiveLayer();
97 
98  // If after showing the dialog the user has removed the active layer,
99  // then select a new active layer (front copper layer).
100  if( !GetBoard()->GetEnabledLayers()[ cur_layer ] )
101  cur_layer = F_Cu;
102 
103  SetActiveLayer( cur_layer );
104 
105  OnModify();
108 
109  if( IsGalCanvasActive() )
110  static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->SyncLayersVisibility( GetBoard() );
111  }
112  break;
113 
114  case ID_PCB_LIB_WIZARD:
116  {
117  bool tableChanged = false;
118  int r = 0;
119 
120  if( id == ID_PCB_LIB_TABLE_EDIT )
121  r = InvokePcbLibTableEditor( this, &GFootprintTable, Prj().PcbFootprintLibs() );
122  else
123  r = InvokeFootprintWizard( this, &GFootprintTable, Prj().PcbFootprintLibs() );
124 
125  if( r & 1 )
126  {
127  try
128  {
130 
131  GFootprintTable.Format( &sf, 0 );
132  tableChanged = true;
133  }
134  catch( const IO_ERROR& ioe )
135  {
136  wxString msg = wxString::Format( _(
137  "Error occurred saving the global footprint library "
138  "table:\n\n%s" ),
139  GetChars( ioe.What().GetData() )
140  );
141  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
142  }
143  }
144 
145  // If no board file is defined, do not save the project specific library table. It
146  // is kept in memory and created in the path when the new board is saved.
147  if( (r & 2) && !GetBoard()->GetFileName().IsEmpty() )
148  {
149  wxString tblName = Prj().FootprintLibTblName();
150 
151  try
152  {
153  Prj().PcbFootprintLibs()->Save( tblName );
154  tableChanged = true;
155  }
156  catch( const IO_ERROR& ioe )
157  {
158  wxString msg = wxString::Format( _(
159  "Error occurred saving project specific footprint library "
160  "table:\n\n%s" ),
161  GetChars( ioe.What() )
162  );
163  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
164  }
165  }
166 
167  FOOTPRINT_VIEWER_FRAME* viewer;
168 
169  if( tableChanged && (viewer = (FOOTPRINT_VIEWER_FRAME*)Kiway().Player( FRAME_PCB_MODULE_VIEWER, false )) != NULL )
170  {
171  viewer->ReCreateLibraryList();
172  }
173  }
174  break;
175 
177 #ifdef BUILD_GITHUB_PLUGIN
179 #endif
180  break;
181 
183  {
184  DIALOG_PADS_MASK_CLEARANCE dlg( this );
185 
186  if( dlg.ShowModal() == 1 && IsGalCanvasActive() )
187  {
188  for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
189  GetGalCanvas()->GetView()->Update( module );
190 
191  GetGalCanvas()->Refresh();
192  }
193  }
194  break;
195 
196  case wxID_PREFERENCES:
197  {
198  DIALOG_GENERALOPTIONS dlg( this );
199  dlg.ShowModal();
200  }
201  break;
202 
203  case ID_PCB_PAD_SETUP:
204  InstallPadOptionsFrame( NULL );
205  break;
206 
207  case ID_CONFIG_SAVE:
208  SaveProjectSettings( true );
209  break;
210 
211  case ID_CONFIG_READ:
212  {
213  fn = GetBoard()->GetFileName();
214  fn.SetExt( ProjectFileExtension );
215 
216  wxFileDialog dlg( this, _( "Read Project File" ), fn.GetPath(),
217  fn.GetFullName(), ProjectFileWildcard,
218  wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
219 
220  if( dlg.ShowModal() == wxID_CANCEL )
221  break;
222 
223  if( !wxFileExists( dlg.GetPath() ) )
224  {
225  wxString msg = wxString::Format( _(
226  "File %s not found" ),
227  GetChars( dlg.GetPath() )
228  );
229  DisplayError( this, msg );
230  break;
231  }
232 
233  wxString pro_file = dlg.GetPath();
234 
235  Prj().ConfigLoad( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters(), pro_file );
236  }
237  break;
238 
239  // Hotkey IDs
242  break;
243 
246  break;
247 
250  break;
251 
253  // Display current hotkey list for Pcbnew.
255  break;
256 
257  default:
258  DisplayErrorMessage( this, "Unkown ID in Process Config",
259  wxString::Format( "PCB_EDIT_FRAME::Process_Config received ID %d", id ) );
260  break;
261  }
262 }
263 
264 
266 {
267  wxLogDebug( wxT( "Loading project '%s' settings." ),
268  GetChars( Prj().GetProjectFullName() ) );
269 
270  bool rc = Prj().ConfigLoad( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters() );
271 
272  // Load the page layout decr file, from the filename stored in
273  // BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
274  // If empty, or not existing, the default descr is loaded
276  wxString pg_fullfilename = WORKSHEET_LAYOUT::MakeFullFileName(
278  Prj().GetProjectPath() );
279 
280  pglayout.SetPageLayout( pg_fullfilename );
281 
282  return rc;
283 }
284 
285 
286 void PCB_EDIT_FRAME::SaveProjectSettings( bool aAskForSave )
287 {
288  wxFileName fn = Prj().GetProjectFullName();
289 
290  if( aAskForSave )
291  {
292  wxFileDialog dlg( this, _( "Save Project File" ),
293  fn.GetPath(), fn.GetFullName(),
294  ProjectFileWildcard, wxFD_SAVE | wxFD_CHANGE_DIR );
295 
296  if( dlg.ShowModal() == wxID_CANCEL )
297  return;
298 
299  fn = dlg.GetPath();
300  }
301 
302  wxString pro_name = fn.GetFullPath();
303 
304  Prj().ConfigSave( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters(), pro_name );
305 }
306 
307 
309 {
310  PARAM_CFG_ARRAY pca;
311 
312  // This one cannot be cached because some settings are going to/from the BOARD,
313  // so pointers into that cannot be saved for long.
314 
315  pca.push_back( new PARAM_CFG_FILENAME( wxT( "PageLayoutDescrFile" ),
317 
318  pca.push_back( new PARAM_CFG_FILENAME( wxT( "LastNetListRead" ), &m_lastNetListRead ) );
319 
321 
322  return pca;
323 }
324 
325 
327 {
329 
330  if( m_configParams.empty() )
331  {
332 
333  // Units used in dialogs and toolbars
334  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "Units" ),
335  (int*)&g_UserUnit, MILLIMETRES ) );
336 
337  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayPolarCoords" ),
338  &displ_opts->m_DisplayPolarCood, false ) );
339  // Display options and modes:
340  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "ShowNetNamesMode" ),
341  &displ_opts->m_DisplayNetNamesMode, 3, 0, 3 ) );
342  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayTrackFilled" ),
343  &displ_opts->m_DisplayPcbTrackFill, true ) );
344  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "TrackDisplayClearance" ),
345  (int*) &displ_opts->m_ShowTrackClearanceMode,
347  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadFill" ),
348  &displ_opts->m_DisplayPadFill, true ) );
349  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ViaFill" ),
350  &displ_opts->m_DisplayViaFill, true ) );
351  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadAffG" ),
352  &displ_opts->m_DisplayPadIsol, true ) );
353  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadSNum" ),
354  &displ_opts->m_DisplayPadNum, true ) );
355  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ModAffC" ),
356  &displ_opts->m_DisplayModEdgeFill, FILLED ) );
357  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ModAffT" ),
358  &displ_opts->m_DisplayModTextFill, FILLED ) );
359  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PcbAffT" ),
360  &displ_opts->m_DisplayDrawItemsFill, FILLED ) );
361  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "PcbShowZonesMode" ),
362  &displ_opts->m_DisplayZonesMode, 0, 0, 2 ) );
363 
364  // layer colors:
365 
366 
367  // Miscellaneous:
368  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "RotationAngle" ), &m_rotationAngle,
369  900, 1, 900 ) );
370  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "MaxLnkS" ),
371  &displ_opts->m_MaxLinksShowed,
372  3, 0, 15 ) );
373 
374 //FIXMEd
375 /* m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "TwoSegT" ),
376  &g_TwoSegmentTrackBuild, true ) );
377  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "SegmPcb45Only" )
378  , &g_Segments_45_Only, true ) );*/
379  }
380 
381  return m_configParams;
382 }
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
Definition: pcbframe.cpp:999
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:307
Definition of class FOOTPRINT_EDIT_FRAME.
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)
This file is part of the common library TODO brief description.
This file is part of the common library.
const wxString ProjectFileExtension
Class BOARD to handle a board.
const wxString ProjectFileWildcard
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.
Definition: modview_frame.h:44
MODULE * Next() const
Definition: class_module.h:100
bool LoadProjectSettings()
Load the current project'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 ...
Definition: tool_pcb.cpp:711
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96
bool m_DisplayModEdgeFill
Definition: pcbstruct.h:69
BOARD * GetBoard() const
PARAM_CFG_ARRAY & GetConfigurationSettings()
Function GetConfigurationSettings returns the Pcbnew applications settings list.
bool m_DisplayPolarCood
Definition: pcbstruct.h:76
wxAuiManager m_auimgr
Definition: wxstruct.h:144
bool m_show_microwave_tools
Definition: wxPcbStruct.h:247
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:311
This file contains miscellaneous commonly used macros and functions.
bool m_show_layer_manager_tools
Definition: wxPcbStruct.h:248
Board plot function definition file.
struct EDA_HOTKEY_CONFIG g_Board_Editor_Hokeys_Descr[]
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
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.
bool m_DisplayPcbTrackFill
Definition: pcbstruct.h:71
PCB_LAYER_ID
A quick note on layer IDs:
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:85
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
bool m_DisplayDrawItemsFill
Definition: pcbstruct.h:84
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:828
int m_DisplayZonesMode
Definition: pcbstruct.h:77
Configuration parameter - Boolean Class.
void Save(const wxString &aFileName) const
Function Save.
VTBL_ENTRY const wxString FootprintLibTblName() const
Function FootprintLibTblName returns the path and filename of this project's fp-lib-table, i.e.
Definition: project.cpp:114
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:1377
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.
Class DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
Definition: pcbstruct.h:62
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 m_lastNetListRead
Last net list read with relative path.
Definition: wxPcbStruct.h:100
TRACE_CLEARANCE_DISPLAY_MODE_T m_ShowTrackClearanceMode
How trace clearances are displayed.
Definition: pcbstruct.h:74
void InstallHotkeyFrame(EDA_BASE_FRAME *aParent, EDA_HOTKEY_CONFIG *aHotkeys)
Function InstallHotkeyFrame Create a hotkey editor dialog window with the provided hotkey configurati...
bool m_DisplayPadFill
Definition: pcbstruct.h:65
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
bool m_DisplayPadIsol
Definition: pcbstruct.h:68
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
bool m_DisplayPadNum
Definition: pcbstruct.h:67
static const wxString MakeFullFileName(const wxString &aShortFileName, const wxString &aProjectPath)
Static function.
void ReCreateLibraryList()
Function ReCreateLibraryList.
The common library.
int m_DisplayNetNamesMode
Definition: pcbstruct.h:78
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
int m_MaxLinksShowed
Definition: pcbstruct.h:86
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:836
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.
Definition: wxPcbStruct.h:98
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:342
Module description (excepted pads)
void ReFillLayerWidget()
Function ReFillLayerWidget changes out all the layers in m_Layers and may be called upon loading a ne...
Definition: pcbframe.cpp:578
void ImportHotkeyConfigFromFile(EDA_HOTKEY_CONFIG *aDescList, const wxString &aDefaultShortname)
Function ImportHotkeyConfigFromFile Prompt the user for an old hotkey file to read, and read it.
bool m_DisplayViaFill
Definition: pcbstruct.h:66
#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:71
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...
Definition: pcbframe.cpp:888
bool m_DisplayModTextFill
Definition: pcbstruct.h:70
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...