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 <wxPcbStruct.h>
43 #include <class_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 <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  OnModify();
107 
108  if( IsGalCanvasActive() )
109  static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->SyncLayersVisibility( GetBoard() );
110 
111  GetCanvas()->Refresh();
112  }
113  break;
114 
115  case ID_PCB_LIB_WIZARD:
117  {
118  bool tableChanged = false;
119  int r = 0;
120 
121  if( id == ID_PCB_LIB_TABLE_EDIT )
122  r = InvokePcbLibTableEditor( this, &GFootprintTable, Prj().PcbFootprintLibs() );
123  else
124  r = InvokeFootprintWizard( this, &GFootprintTable, Prj().PcbFootprintLibs() );
125 
126  if( r & 1 )
127  {
128  try
129  {
131 
132  GFootprintTable.Format( &sf, 0 );
133  tableChanged = true;
134  }
135  catch( const IO_ERROR& ioe )
136  {
137  wxString msg = wxString::Format( _(
138  "Error occurred saving the global footprint library "
139  "table:\n\n%s" ),
140  GetChars( ioe.What().GetData() )
141  );
142  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
143  }
144  }
145 
146  // If no board file is defined, do not save the project specific library table. It
147  // is kept in memory and created in the path when the new board is saved.
148  if( (r & 2) && !GetBoard()->GetFileName().IsEmpty() )
149  {
150  wxString tblName = Prj().FootprintLibTblName();
151 
152  try
153  {
154  Prj().PcbFootprintLibs()->Save( tblName );
155  tableChanged = true;
156  }
157  catch( const IO_ERROR& ioe )
158  {
159  wxString msg = wxString::Format( _(
160  "Error occurred saving project specific footprint library "
161  "table:\n\n%s" ),
162  GetChars( ioe.What() )
163  );
164  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
165  }
166  }
167 
168  FOOTPRINT_VIEWER_FRAME* viewer;
169 
170  if( tableChanged && (viewer = (FOOTPRINT_VIEWER_FRAME*)Kiway().Player( FRAME_PCB_MODULE_VIEWER, false )) != NULL )
171  {
172  viewer->ReCreateLibraryList();
173  }
174  }
175  break;
176 
178 #ifdef BUILD_GITHUB_PLUGIN
180 #endif
181  break;
182 
184  {
185  DIALOG_PADS_MASK_CLEARANCE dlg( this );
186 
187  if( dlg.ShowModal() == 1 && IsGalCanvasActive() )
188  {
189  for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
190  GetGalCanvas()->GetView()->Update( module );
191 
192  GetGalCanvas()->Refresh();
193  }
194  }
195  break;
196 
197  case wxID_PREFERENCES:
198  {
199  DIALOG_GENERALOPTIONS dlg( this );
200  dlg.ShowModal();
201  }
202  break;
203 
204  case ID_PCB_PAD_SETUP:
205  InstallPadOptionsFrame( NULL );
206  break;
207 
208  case ID_CONFIG_SAVE:
209  SaveProjectSettings( true );
210  break;
211 
212  case ID_CONFIG_READ:
213  {
214  fn = GetBoard()->GetFileName();
215  fn.SetExt( ProjectFileExtension );
216 
217  wxFileDialog dlg( this, _( "Read Project File" ), fn.GetPath(),
218  fn.GetFullName(), ProjectFileWildcard(),
219  wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
220 
221  if( dlg.ShowModal() == wxID_CANCEL )
222  break;
223 
224  if( !wxFileExists( dlg.GetPath() ) )
225  {
226  wxString msg = wxString::Format( _(
227  "File %s not found" ),
228  GetChars( dlg.GetPath() )
229  );
230  DisplayError( this, msg );
231  break;
232  }
233 
234  wxString pro_file = dlg.GetPath();
235 
236  Prj().ConfigLoad( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters(), pro_file );
237  }
238  break;
239 
240  // Hotkey IDs
243  break;
244 
247  break;
248 
251  break;
252 
254  // Display current hotkey list for Pcbnew.
256  break;
257 
258  default:
259  DisplayErrorMessage( this, "Unkown ID in Process Config",
260  wxString::Format( "PCB_EDIT_FRAME::Process_Config received ID %d", id ) );
261  break;
262  }
263 }
264 
265 
267 {
268  wxLogDebug( wxT( "Loading project '%s' settings." ),
269  GetChars( Prj().GetProjectFullName() ) );
270 
271  bool rc = Prj().ConfigLoad( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters() );
272 
273  // Load the page layout decr file, from the filename stored in
274  // BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
275  // If empty, or not existing, the default descr is loaded
277  wxString pg_fullfilename = WORKSHEET_LAYOUT::MakeFullFileName(
279  Prj().GetProjectPath() );
280 
281  pglayout.SetPageLayout( pg_fullfilename );
282 
283  return rc;
284 }
285 
286 
287 void PCB_EDIT_FRAME::SaveProjectSettings( bool aAskForSave )
288 {
289  wxFileName fn = Prj().GetProjectFullName();
290 
291  if( aAskForSave )
292  {
293  wxFileDialog dlg( this, _( "Save Project File" ),
294  fn.GetPath(), fn.GetFullName(),
295  ProjectFileWildcard(), wxFD_SAVE | wxFD_CHANGE_DIR );
296 
297  if( dlg.ShowModal() == wxID_CANCEL )
298  return;
299 
300  fn = dlg.GetPath();
301  }
302 
303  wxString pro_name = fn.GetFullPath();
304 
305  Prj().ConfigSave( Kiface().KifaceSearch(), GROUP_PCB, GetProjectFileParameters(), pro_name );
306 }
307 
308 
310 {
311  PARAM_CFG_ARRAY pca;
312 
313  // This one cannot be cached because some settings are going to/from the BOARD,
314  // so pointers into that cannot be saved for long.
315 
316  pca.push_back( new PARAM_CFG_FILENAME( wxT( "PageLayoutDescrFile" ),
318 
319  pca.push_back( new PARAM_CFG_FILENAME( wxT( "LastNetListRead" ), &m_lastNetListRead ) );
320 
322 
323  return pca;
324 }
325 
326 
328 {
329  auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions();
330 
331  if( m_configParams.empty() )
332  {
333 
334  // Units used in dialogs and toolbars
335  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "Units" ),
336  (int*)&g_UserUnit, MILLIMETRES ) );
337 
338  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayPolarCoords" ),
339  &displ_opts->m_DisplayPolarCood, false ) );
340  // Display options and modes:
341  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "ShowNetNamesMode" ),
342  &displ_opts->m_DisplayNetNamesMode, 3, 0, 3 ) );
343  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayTrackFilled" ),
344  &displ_opts->m_DisplayPcbTrackFill, true ) );
345  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "TrackDisplayClearance" ),
346  (int*) &displ_opts->m_ShowTrackClearanceMode,
348  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadFill" ),
349  &displ_opts->m_DisplayPadFill, true ) );
350  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ViaFill" ),
351  &displ_opts->m_DisplayViaFill, true ) );
352  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadAffG" ),
353  &displ_opts->m_DisplayPadIsol, true ) );
354  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PadSNum" ),
355  &displ_opts->m_DisplayPadNum, true ) );
356  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ModAffC" ),
357  &displ_opts->m_DisplayModEdgeFill, FILLED ) );
358  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "ModAffT" ),
359  &displ_opts->m_DisplayModTextFill, FILLED ) );
360  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "PcbAffT" ),
361  &displ_opts->m_DisplayDrawItemsFill, FILLED ) );
362  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "PcbShowZonesMode" ),
363  &displ_opts->m_DisplayZonesMode, 0, 0, 2 ) );
364 
365  // layer colors:
366 
367 
368  // Miscellaneous:
369  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "RotationAngle" ), &m_rotationAngle,
370  900, 1, 900 ) );
371  m_configParams.push_back( new PARAM_CFG_INT( true, wxT( "MaxLnkS" ),
372  &displ_opts->m_MaxLinksShowed,
373  3, 0, 15 ) );
374 
375 //FIXMEd
376 /* m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "TwoSegT" ),
377  &g_TwoSegmentTrackBuild, true ) );
378  m_configParams.push_back( new PARAM_CFG_BOOL( true, wxT( "SegmPcb45Only" )
379  , &g_Segments_45_Only, true ) );*/
380  }
381 
382  return m_configParams;
383 }
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
Definition: pcbframe.cpp:1001
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
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.
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:325
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:337
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.
Definition: modview_frame.h:44
MODULE * Next() const
Definition: class_module.h:120
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:714
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.
wxAuiManager m_auimgr
Definition: wxstruct.h:149
bool m_show_microwave_tools
Definition: wxPcbStruct.h:244
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:245
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.
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
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:87
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 IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:862
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'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:1385
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.
Definition: wxPcbStruct.h:100
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:870
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: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...
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.
#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:73
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:890
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...