pcbnew_config.cpp 25.9 KB
Newer Older
1 2 3
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
4 5 6 7
 * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

27 28 29
/**
 * @file pcbnew_config.cpp
 */
30

31 32 33 34 35 36 37 38 39 40 41 42 43
#include <fctsys.h>
#include <appl_wxstruct.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <gestfich.h>
#include <xnode.h>
#include <macros.h>
#include <pcbcommon.h>
#include <wxPcbStruct.h>
#include <class_board_design_settings.h>
#include <plot_common.h>
#include <worksheet.h>
#include <dialog_hotkeys_editor.h>
44
#include <fp_lib_table.h>
Dick Hollenbeck's avatar
Dick Hollenbeck committed
45
#include <fp_lib_table_lexer.h>
46
#include <worksheet_shape_builder.h>
47

48
#include <class_board.h>
49 50 51 52 53
#include <pcbplot.h>
#include <pcbnew.h>
#include <pcbnew_id.h>
#include <hotkeys.h>
#include <pcbnew_config.h>
54 55
#include <module_editor_frame.h>
#include <modview_frame.h>
56

57
#include <invoke_pcb_dialog.h>
58 59
#include <dialog_mask_clearance.h>
#include <dialog_general_options.h>
60
#include <wildcards_and_files_ext.h>
61

62

63
void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
64
{
65 66
    int         id = event.GetId();
    wxFileName  fn;
dickelbeck's avatar
dickelbeck committed
67 68 69

    switch( id )
    {
70
    case ID_MENU_PCB_SHOW_HIDE_LAYERS_MANAGER_DIALOG:
71 72 73 74 75 76 77
        m_show_layer_manager_tools = ! m_show_layer_manager_tools;
        m_auimgr.GetPane( wxT( "m_LayersManagerToolBar" ) ).Show( m_show_layer_manager_tools );
        m_auimgr.Update();

        GetMenuBar()->SetLabel( ID_MENU_PCB_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
                                m_show_layer_manager_tools ?
                                _("Hide &Layers Manager" ) : _("Show &Layers Manager" ));
dickelbeck's avatar
dickelbeck committed
78 79
        break;

80
    case ID_PCB_LAYERS_SETUP:
jean-pierre charras's avatar
jean-pierre charras committed
81
        InstallDialogLayerSetup();
82
        break;
83

84
    case ID_CONFIG_REQ:
85
        InstallConfigFrame();
dickelbeck's avatar
dickelbeck committed
86 87
        break;

88
    case ID_PCB_LIB_TABLE_EDIT:
89 90
    {
        int r = InvokePcbLibTableEditor( this, m_globalFootprintTable, m_footprintLibTable );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
91

92 93
        if( r & 1 )
        {
94 95 96 97 98 99 100 101 102 103
            try
            {
                FILE_OUTPUTFORMATTER sf( FP_LIB_TABLE::GetGlobalTableFileName() );
                m_globalFootprintTable->Format( &sf, 0 );
            }
            catch( IO_ERROR& ioe )
            {
                wxString msg;
                msg.Printf( _( "Error occurred saving the global footprint library "
                               "table:\n\n%s" ), ioe.errorText.GetData() );
104
                wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
105
            }
106
        }
Dick Hollenbeck's avatar
Dick Hollenbeck committed
107

108 109 110
        // If no board file is defined, do not save the project specific library table.  It
        // is kept in memory and created in the path when the new board is saved.
        if( (r & 2) && !GetBoard()->GetFileName().IsEmpty() )
111 112
        {
            wxFileName fn = GetBoard()->GetFileName();
Dick Hollenbeck's avatar
Dick Hollenbeck committed
113

114 115 116 117 118 119 120 121 122
            try
            {
                m_footprintLibTable->Save( fn );
            }
            catch( IO_ERROR& ioe )
            {
                wxString msg;
                msg.Printf( _( "Error occurred saving project specific footprint library "
                               "table:\n\n%s" ), ioe.errorText.GetData() );
123
                wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
124
            }
125
        }
126 127
    }

128 129
        break;

130 131 132 133 134 135 136
    case ID_PCB_MASK_CLEARANCE:
        {
            DIALOG_PADS_MASK_CLEARANCE dlg( this );
            dlg.ShowModal();
        }
        break;

137
    case wxID_PREFERENCES:
138
        {
139
            DIALOG_GENERALOPTIONS dlg( this );
140 141 142 143
            dlg.ShowModal();
        }
        break;

dickelbeck's avatar
dickelbeck committed
144
    case ID_PCB_PAD_SETUP:
charras's avatar
charras committed
145
        InstallPadOptionsFrame( NULL );
dickelbeck's avatar
dickelbeck committed
146 147 148
        break;

    case ID_CONFIG_SAVE:
149
        SaveProjectSettings( true );
dickelbeck's avatar
dickelbeck committed
150 151 152
        break;

    case ID_CONFIG_READ:
153
        {
154
            fn = GetBoard()->GetFileName();
155
            fn.SetExt( ProjectFileExtension );
156

157 158 159
            wxFileDialog dlg( this, _( "Read Project File" ), fn.GetPath(),
                              fn.GetFullName(), ProjectFileWildcard,
                              wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
160

161 162
            if( dlg.ShowModal() == wxID_CANCEL )
                break;
163

164 165 166 167 168 169 170
            if( !wxFileExists( dlg.GetPath() ) )
            {
                wxString msg;
                msg.Printf( _( "File %s not found" ), GetChars( dlg.GetPath() ) );
                DisplayError( this, msg );
                break;
            }
dickelbeck's avatar
dickelbeck committed
171

172 173
            LoadProjectSettings( dlg.GetPath() );
        }
174
        break;
dickelbeck's avatar
dickelbeck committed
175

176
    // Hotkey IDs
177
    case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG:
178
        ExportHotkeyConfigToFile( g_Board_Editor_Hokeys_Descr );
dickelbeck's avatar
dickelbeck committed
179 180
        break;

181
    case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG:
182
        ImportHotkeyConfigFromFile( g_Board_Editor_Hokeys_Descr );
dickelbeck's avatar
dickelbeck committed
183 184
        break;

185
    case ID_PREFERENCES_HOTKEY_SHOW_EDITOR:
186
        InstallHotkeyFrame( this, g_Board_Editor_Hokeys_Descr );
dickelbeck's avatar
dickelbeck committed
187 188
        break;

189
    case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST:
190
        // Display current hotkey list for Pcbnew.
191
        DisplayHotkeyList( this, g_Board_Editor_Hokeys_Descr );
dickelbeck's avatar
dickelbeck committed
192 193
        break;

194
    // Macros IDs
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
195 196 197 198 199 200 201 202
    case ID_PREFRENCES_MACROS_SAVE:
        SaveMacros();
        break;

    case ID_PREFRENCES_MACROS_READ:
        ReadMacros();
        break;

dickelbeck's avatar
dickelbeck committed
203
    default:
204
        DisplayError( this, wxT( "PCB_EDIT_FRAME::Process_Config error" ) );
dickelbeck's avatar
dickelbeck committed
205
    }
206 207 208
}


209
bool PCB_EDIT_FRAME::LoadProjectSettings( const wxString& aProjectFileName )
210
{
211 212
    wxLogDebug( wxT( "Loading project <%s> settings." ), GetChars( aProjectFileName ) );

213
    wxFileName fn = aProjectFileName;
214

215 216 217
    if( fn.GetExt() != ProjectFileExtension )
        fn.SetExt( ProjectFileExtension );

218
    wxGetApp().RemoveLibraryPath( g_UserLibDirBuffer );
219

Dick Hollenbeck's avatar
Dick Hollenbeck committed
220
    // Initialize default values.
221
    g_LibraryNames.Clear();
222

223
    wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP, GetProjectFileParameters(), false );
224

Dick Hollenbeck's avatar
Dick Hollenbeck committed
225
    // User library path takes precedent over default library search paths.
226
    wxGetApp().InsertLibraryPath( g_UserLibDirBuffer, 1 );
227

Dick Hollenbeck's avatar
Dick Hollenbeck committed
228 229 230 231 232 233
    // Dick 5-Feb-2012: I don't agree with this, the BOARD contents should dictate
    // what is visible or not, even initially.  And since PCB_EDIT_FRAME projects settings
    // have no control over what is visible (see PCB_EDIT_FRAME::GetProjectFileParameters())
    // this is recklessly turning on things the user may not want to see.
#if 0

234
    /* Reset the items visibility flag when loading a new configuration because it could
Dick Hollenbeck's avatar
Dick Hollenbeck committed
235
     * create SERIOUS mistakes for the user if board items are not visible after loading
236
     * a board.  Grid and ratsnest can be left to their previous state.
237
     */
238 239
    bool showGrid = IsElementVisible( GRID_VISIBLE );
    bool showRats = IsElementVisible( RATSNEST_VISIBLE );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
240

241
    SetVisibleAlls();
Dick Hollenbeck's avatar
Dick Hollenbeck committed
242

243 244
    SetElementVisibility( GRID_VISIBLE, showGrid );
    SetElementVisibility( RATSNEST_VISIBLE, showRats );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
245 246
#endif

247 248 249 250 251 252 253
    fn = GetBoard()->GetFileName();

    // Check if a project footprint table is defined and load it.  If no project footprint
    // table is defined, then the global library table is the footprint library table.
#if defined( USE_FP_LIB_TABLE )
    delete m_footprintLibTable;

254 255 256
    wxFileName projectFpLibTableFileName;

    projectFpLibTableFileName = FP_LIB_TABLE::GetProjectFileName( fn );
257 258 259 260
    m_footprintLibTable = new FP_LIB_TABLE();

    try
    {
261
        m_footprintLibTable->Load( projectFpLibTableFileName, m_globalFootprintTable );
262 263 264 265 266
    }
    catch( IO_ERROR ioe )
    {
        DisplayError( this, ioe.errorText );
    }
267 268 269 270 271 272 273 274 275 276 277 278

    FOOTPRINT_EDIT_FRAME* editFrame = FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor();

    if( editFrame )
        editFrame->SetFootprintLibTable( m_footprintLibTable );

    FOOTPRINT_VIEWER_FRAME* viewFrame = FOOTPRINT_VIEWER_FRAME::GetActiveFootprintViewer();

    if( viewFrame )
        viewFrame->SetFootprintLibTable( m_footprintLibTable );

    FP_LIB_TABLE::SetProjectPathEnvVariable( fn );
279 280
#endif

281 282 283 284
    // Load the page layout decr file, from the filename stored in
    // BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
    // If empty, the default descr is loaded
    WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
285
    pglayout.SetPageLayout( BASE_SCREEN::m_PageLayoutDescrFileName );
286

287
    return true;
288 289
}

dickelbeck's avatar
dickelbeck committed
290

291
void PCB_EDIT_FRAME::SaveProjectSettings( bool aAskForSave )
292
{
293 294
    wxFileName fn;

295
    fn = GetBoard()->GetFileName();
296 297
    fn.SetExt( ProjectFileExtension );

298 299 300 301 302
    if( aAskForSave )
    {
        wxFileDialog dlg( this, _( "Save Project File" ),
                          fn.GetPath(), fn.GetFullName(),
                          ProjectFileWildcard, wxFD_SAVE | wxFD_CHANGE_DIR );
303

304 305
        if( dlg.ShowModal() == wxID_CANCEL )
            return;
dickelbeck's avatar
dickelbeck committed
306

307 308 309 310 311
        wxGetApp().WriteProjectConfig( dlg.GetPath(), GROUP, GetProjectFileParameters() );
    }

    else
        wxGetApp().WriteProjectConfig( fn.GetFullPath(), GROUP, GetProjectFileParameters() );
312 313 314
}


Dick Hollenbeck's avatar
Dick Hollenbeck committed
315
PARAM_CFG_ARRAY PCB_EDIT_FRAME::GetProjectFileParameters()
316
{
Dick Hollenbeck's avatar
Dick Hollenbeck committed
317
    PARAM_CFG_ARRAY         pca;
318

319 320 321
    pca.push_back( new PARAM_CFG_FILENAME( wxT( "PageLayoutDescrFile" ),
                                          &BASE_SCREEN::m_PageLayoutDescrFileName ) );

Dick Hollenbeck's avatar
Dick Hollenbeck committed
322
    pca.push_back( new PARAM_CFG_FILENAME( wxT( "LibDir" ),&g_UserLibDirBuffer,
323
                                           GROUPLIB ) );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
324
    pca.push_back( new PARAM_CFG_LIBNAME_LIST( wxT( "LibName" ),
325
                                               &g_LibraryNames,  GROUPLIB ) );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
326

Dick Hollenbeck's avatar
Dick Hollenbeck committed
327
    pca.push_back( new PARAM_CFG_FILENAME( wxT( "LastNetListRead" ),
328
                                           &m_lastNetListRead ) );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
329

330
    pca.push_back( new PARAM_CFG_BOOL( wxT( "UseCmpFile" ),
331
                                       &m_useCmpFileForFpNames, true ) );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
332 333
    GetBoard()->GetDesignSettings().AppendConfigs( &pca );

Dick Hollenbeck's avatar
Dick Hollenbeck committed
334
    return pca;
335 336 337
}


338
PARAM_CFG_ARRAY& PCB_EDIT_FRAME::GetConfigurationSettings()
339 340 341 342
{
    if( !m_configSettings.empty() )
        return m_configSettings;

343
    // Units used in dialogs and toolbars
344 345
    m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "Units" ),
                                                   (int*)&g_UserUnit, MILLIMETRES ) );
346 347 348 349 350

    m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayPolarCoords" ),
                                                    &DisplayOpt.DisplayPolarCood, false ) );
    // Display options and modes:
    m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "ViaHoleDisplayMode" ),
351
                                                   (int*) &DisplayOpt.m_DisplayViaMode,
352 353 354 355
                                                   VIA_SPECIAL_HOLE_SHOW, VIA_HOLE_NOT_SHOW,
                                                   OPT_VIA_HOLE_END - 1 ) );
    m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "ShowNetNamesMode" ),
                                                   &DisplayOpt.DisplayNetNamesMode, 3, 0, 3 ) );
356 357
    m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "DisplayTrackFilled" ),
                                                    &DisplayOpt.DisplayPcbTrackFill, true ) );
358
    m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "TrackDisplayClearance" ),
359
                                                   (int*) &DisplayOpt.ShowTrackClearanceMode,
360 361
                                                   SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS ) );
    m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "PadFill" ),
362
                                                    &DisplayOpt.DisplayPadFill, true ) );
363
    m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "ViaFill" ),
364
                                                    &DisplayOpt.DisplayViaFill, true ) );
365
    m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "PadAffG" ),
366
                                                    &DisplayOpt.DisplayPadIsol, true ) );
367
    m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "PadSNum" ),
368
                                                    &DisplayOpt.DisplayPadNum, true ) );
369 370 371 372 373 374
    m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "ModAffC" ),
                                                   &DisplayOpt.DisplayModEdge, FILLED, 0, 2 ) );
    m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "ModAffT" ),
                                                   &DisplayOpt.DisplayModText, FILLED, 0, 2 ) );
    m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "PcbAffT" ),
                                                   &DisplayOpt.DisplayDrawItems, FILLED, 0, 2 ) );
375 376
    m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "PcbShowZonesMode" ),
                                                   &DisplayOpt.DisplayZonesMode, 0, 0, 2 ) );
377 378

    // Colors:
379
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer0Ex" ), LOC_COLOR( 0 ),
380
                                                        GREEN ) );
381
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer1Ex" ), LOC_COLOR( 1 ),
382
                                                        BLUE ) );
383
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer2Ex" ), LOC_COLOR( 2 ),
384
                                                        LIGHTGRAY ) );
385
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer3Ex" ), LOC_COLOR( 3 ),
386
                                                        MAGENTA ) );
387
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer4Ex" ), LOC_COLOR( 4 ),
388
                                                        RED ) );
389
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer5Ex" ), LOC_COLOR( 5 ),
390
                                                        MAGENTA ) );
391
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer6Ex" ), LOC_COLOR( 6 ),
392
                                                        BROWN ) );
393
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer7Ex" ), LOC_COLOR( 7 ),
394
                                                        MAGENTA ) );
395
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer8Ex" ), LOC_COLOR( 8 ),
396
                                                        LIGHTGRAY ) );
397
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer9Ex" ), LOC_COLOR( 9 ),
398
                                                        BLUE ) );
399
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer10Ex" ), LOC_COLOR( 10 ),
400
                                                        GREEN ) );
401
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer11Ex" ), LOC_COLOR( 11 ),
402
                                                        CYAN ) );
403
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer12Ex" ), LOC_COLOR( 12 ),
404
                                                        LIGHTRED ) );
405
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer13Ex" ), LOC_COLOR( 13 ),
406
                                                        LIGHTMAGENTA ) );
407
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer14Ex" ), LOC_COLOR( 14 ),
408
                                                        YELLOW ) );
409
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer15Ex" ), LOC_COLOR( 15 ),
410
                                                        RED ) );
411
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer16Ex" ), LOC_COLOR( 16 ),
412
                                                        BLUE ) );
413
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer17Ex" ), LOC_COLOR( 17 ),
414
                                                        MAGENTA ) );
415
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer18Ex" ), LOC_COLOR( 18 ),
416
                                                        LIGHTCYAN ) );
417
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer19Ex" ), LOC_COLOR( 19 ),
418
                                                        RED ) );
419
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer20Ex" ), LOC_COLOR( 20 ),
420
                                                        MAGENTA ) );
421
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer21Ex" ), LOC_COLOR( 21 ),
422
                                                        CYAN ) );
423
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer22Ex" ), LOC_COLOR( 22 ),
424
                                                        BROWN ) );
425
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer23Ex" ), LOC_COLOR( 23 ),
426
                                                        MAGENTA ) );
427
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer24Ex" ), LOC_COLOR( 24 ),
428
                                                        LIGHTGRAY ) );
429
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer25Ex" ), LOC_COLOR( 25 ),
430
                                                        BLUE ) );
431
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer26Ex" ), LOC_COLOR( 26 ),
432
                                                        GREEN ) );
433
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer27Ex" ), LOC_COLOR( 27 ),
434
                                                        YELLOW ) );
435
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer28Ex" ), LOC_COLOR( 28 ),
436
                                                        YELLOW ) );
437
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer29Ex" ), LOC_COLOR( 29 ),
438
                                                        LIGHTMAGENTA ) );
439
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer30Ex" ), LOC_COLOR( 30 ),
440
                                                        YELLOW ) );
441
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLayer31Ex" ), LOC_COLOR( 31 ),
442
                                                        LIGHTGRAY ) );
443
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorTxtFrontEx" ),
444 445
                                                        ITEM_COLOR( MOD_TEXT_FR_VISIBLE ),
                                                        LIGHTGRAY ) );
446
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorTxtBackEx" ),
447 448
                                                        ITEM_COLOR( MOD_TEXT_BK_VISIBLE ),
                                                        BLUE ) );
449
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorTxtInvisEx" ),
450 451
                                                        ITEM_COLOR( MOD_TEXT_INVISIBLE ),
                                                        DARKGRAY ) );
452
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorAnchorEx" ),
453
                                                        ITEM_COLOR( ANCHOR_VISIBLE ), BLUE ) );
454
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorPadBackEx" ),
455
                                                        ITEM_COLOR( PAD_BK_VISIBLE ), GREEN ) );
456
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorPadFrontEx" ),
457
                                                        ITEM_COLOR( PAD_FR_VISIBLE ), RED ) );
458
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorViaThruEx" ),
459 460
                                                        ITEM_COLOR( VIA_THROUGH_VISIBLE ),
                                                        LIGHTGRAY ) );
461
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorViaBBlindEx" ),
462 463
                                                        ITEM_COLOR( VIA_BBLIND_VISIBLE ),
                                                        BROWN ) );
464
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorViaMicroEx" ),
465 466
                                                        ITEM_COLOR( VIA_MICROVIA_VISIBLE ),
                                                        CYAN ) );
467 468 469
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorNonPlatedEx" ),
                                                        ITEM_COLOR( NON_PLATED_VISIBLE ),
                                                        YELLOW ) );
470
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorRatsEx" ),
471 472
                                                        ITEM_COLOR( RATSNEST_VISIBLE ),
                                                        WHITE ) );
473 474

    // Miscellaneous:
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
475 476
    m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "RotationAngle" ), &g_RotationAngle,
                                                   900, 450, 900 ) );
477 478 479
    m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "MaxLnkS" ), &g_MaxLinksShowed,
                                                   3, 0, 15 ) );
    m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "ShowMRa" ),
480
                                                    &g_Show_Module_Ratsnest, true ) );
481
    m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "TwoSegT" ),
482
                                                    &g_TwoSegmentTrackBuild, true ) );
483
    m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "SegmPcb45Only" ), &g_Segments_45_Only,
484
                                                    true ) );
485
    return m_configSettings;
486
}
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
487 488 489 490 491 492 493 494


void PCB_EDIT_FRAME::SaveMacros()
{
    wxXmlDocument xml;
    wxXmlProperty *macrosProp, *hkProp, *xProp, *yProp;
    wxString str, hkStr, xStr, yStr;

495
    wxFileName fn = GetBoard()->GetFileName();
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
496 497 498 499 500 501 502 503
    fn.SetExt( MacrosFileExtension );

    wxFileDialog dlg( this, _( "Save Macros File" ), fn.GetPath(), fn.GetFullName(),
                      MacrosFileWildcard, wxFD_SAVE | wxFD_CHANGE_DIR );

    if( dlg.ShowModal() == wxID_CANCEL )
        return;

504
    XNODE *rootNode = new XNODE( wxXML_ELEMENT_NODE, wxT( "macrosrootnode" ), wxEmptyString );
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
505 506
    xml.SetRoot( rootNode );

507
    for( int number = 9; number >= 0; number-- )
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
508
    {
509 510
        str.Printf( wxT( "%d" ), number );
        macrosProp = new wxXmlProperty( wxT( "number" ), str );
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
511

512 513 514
            XNODE * macrosNode = new XNODE( rootNode, wxXML_ELEMENT_NODE,
                                            wxT( "macros" ), wxEmptyString,
                                            macrosProp );
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
515

516 517 518
        for( std::list<MACROS_RECORD>::reverse_iterator i = m_Macros[number].m_Record.rbegin();
             i != m_Macros[number].m_Record.rend();
             i++ )
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
519
        {
520 521 522
            hkStr.Printf( wxT( "%d" ), i->m_HotkeyCode );
            xStr.Printf( wxT( "%d" ), i->m_Position.x );
            yStr.Printf( wxT( "%d" ), i->m_Position.y );
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
523

524 525 526
            yProp = new wxXmlProperty( wxT( "y" ), yStr );
            xProp = new wxXmlProperty( wxT( "x" ), xStr, yProp );
            hkProp = new wxXmlProperty( wxT( "hkcode" ), hkStr, xProp );
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
527

528 529
            new XNODE( macrosNode, wxXML_ELEMENT_NODE, wxT( "hotkey" ),
                       wxEmptyString, hkProp );
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
530 531 532
        }
    }

533
    xml.SetFileEncoding( wxT( "UTF-8" ) );
534
    xml.Save( dlg.GetFilename() );
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
535 536 537 538 539 540 541 542
}


void PCB_EDIT_FRAME::ReadMacros()
{
    wxString str;
    wxFileName fn;

543
    fn = GetBoard()->GetFileName();
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
    fn.SetExt( MacrosFileExtension );

    wxFileDialog dlg( this, _( "Read Macros File" ), fn.GetPath(),
                      fn.GetFullName(), MacrosFileWildcard,
                      wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );

    if( dlg.ShowModal() == wxID_CANCEL )
        return;

    if( !wxFileExists( dlg.GetPath() ) )
    {
        wxString msg;
        msg.Printf( _( "File %s not found" ), GetChars( dlg.GetPath() ) );
        DisplayError( this, msg );
        return;
    }

    wxXmlDocument xml;

563 564
    xml.SetFileEncoding( wxT( "UTF-8" ) );

Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
565 566 567
    if( !xml.Load( dlg.GetFilename() ) )
            return;

568
    XNODE *macrosNode = (XNODE*) xml.GetRoot()->GetChildren();
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
569 570 571 572 573 574 575

    while( macrosNode )
    {
        int number = -1;

        if( macrosNode->GetName() == wxT( "macros" ) )
        {
576
            number = wxAtoi( macrosNode->GetAttribute( wxT( "number" ), wxT( "-1" ) ) );
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
577 578 579 580 581

            if( number >= 0  && number < 10 )
            {
                m_Macros[number].m_Record.clear();

582 583
                XNODE *hotkeyNode = (XNODE*) macrosNode->GetChildren();

Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
584 585 586 587
                while( hotkeyNode )
                {
                    if( hotkeyNode->GetName() == wxT( "hotkey" ) )
                    {
588 589 590
                        int x = wxAtoi( hotkeyNode->GetAttribute( wxT( "x" ), wxT( "0" ) ) );
                        int y = wxAtoi( hotkeyNode->GetAttribute( wxT( "y" ), wxT( "0" ) ) );
                        int hk = wxAtoi( hotkeyNode->GetAttribute( wxT( "hkcode" ), wxT( "0" ) ) );
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
591 592 593 594 595

                        MACROS_RECORD macros_record;
                        macros_record.m_HotkeyCode = hk;
                        macros_record.m_Position.x = x;
                        macros_record.m_Position.y = y;
596
                        m_Macros[number].m_Record.push_back( macros_record );
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
597 598
                    }

599
                    hotkeyNode = (XNODE*) hotkeyNode->GetNext();
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
600 601 602 603
                }
            }
        }

604
        macrosNode = (XNODE*) macrosNode->GetNext();
Andrey Fedorushkov's avatar
Andrey Fedorushkov committed
605 606
    }
}