eeschema_config.cpp 29.2 KB
Newer Older
1 2 3
/**
 * @file eeschema_config.cpp
 */
CHARRAS's avatar
CHARRAS committed
4

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
 *
 * 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
 */

28 29 30 31 32 33
#include <fctsys.h>
#include <appl_wxstruct.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <gestfich.h>
#include <wxEeschemaStruct.h>
34

35 36 37 38 39 40
#include <eeschema_id.h>
#include <general.h>
#include <libeditframe.h>
#include <eeschema_config.h>
#include <hotkeys.h>
#include <sch_sheet.h>
41
#include <class_libentry.h>
42
#include <worksheet_shape_builder.h>
43

44
#include <dialog_hotkeys_editor.h>
45

46 47 48 49
#include <dialogs/dialog_color_config.h>
#include <dialogs/dialog_eeschema_config.h>
#include <dialogs/dialog_eeschema_options.h>
#include <dialogs/dialog_schematic_find.h>
50

51
#include <wildcards_and_files_ext.h>
52

53
#define HOTKEY_FILENAME         wxT( "eeschema" )
54

55
#define FR_HISTORY_LIST_CNT     10   ///< Maximum number of find and replace strings.
56

57
static EDA_COLOR_T s_layerColor[NB_SCH_LAYERS];
58 59 60 61 62 63 64 65 66 67 68

// The width to draw busses that do not have a specific width
static int s_defaultBusThickness;

int GetDefaultBusThickness()
{
    return s_defaultBusThickness;
}

void SetDefaultBusThickness( int aThickness)
{
69
    if( aThickness >= 1 )
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
        s_defaultBusThickness = aThickness;
    else
        s_defaultBusThickness = 1;
}

/*
 * Default line (in Eeschema units) thickness used to draw/plot items having a
 * default thickness line value (i.e. = 0 ).
 */
static int s_drawDefaultLineThickness;

int GetDefaultLineThickness()
{
    return s_drawDefaultLineThickness;
}

void SetDefaultLineThickness( int aThickness)
{
    if( aThickness >=1 )
        s_drawDefaultLineThickness = aThickness;
    else
        s_drawDefaultLineThickness = 1;
}

94
EDA_COLOR_T GetLayerColor( LayerNumber aLayer )
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
{
    return s_layerColor[aLayer];
}

void SetLayerColor( EDA_COLOR_T aColor, int aLayer )
{
    s_layerColor[aLayer] = aColor;
}

// Color to draw selected items
EDA_COLOR_T GetItemSelectedColor()
{
    return BROWN;
}

// Color to draw items flagged invisible, in libedit (they are invisible
// in Eeschema
EDA_COLOR_T GetInvisibleItemColor()
{
    return DARKGRAY;
}

117 118 119

void LIB_EDIT_FRAME::InstallConfigFrame( wxCommandEvent& event )
{
120
    DIALOG_EESCHEMA_CONFIG CfgFrame( (SCH_EDIT_FRAME *)GetParent(), this );
121 122 123 124 125

    CfgFrame.ShowModal();
}


126 127 128 129 130 131 132 133
void LIB_EDIT_FRAME::OnColorConfig( wxCommandEvent& aEvent )
{
    DIALOG_COLOR_CONFIG dlg( this );

    dlg.ShowModal();
}


134
void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event )
135
{
136 137
    int        id = event.GetId();
    wxFileName fn;
138
    SCH_EDIT_FRAME* schFrame = ( SCH_EDIT_FRAME* ) GetParent();
CHARRAS's avatar
CHARRAS committed
139 140 141

    switch( id )
    {
charras's avatar
charras committed
142
    case ID_CONFIG_SAVE:
143
        schFrame->SaveProjectSettings( false );
charras's avatar
charras committed
144 145 146 147
        break;

    case ID_CONFIG_READ:
    {
148
        fn = g_RootSheet->GetScreen()->GetFileName();
charras's avatar
charras committed
149 150 151 152 153 154 155 156 157
        fn.SetExt( ProjectFileExtension );

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

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

158
        schFrame->LoadProjectFile( dlg.GetPath(), true );
charras's avatar
charras committed
159 160 161 162
    }
    break;


163
    // Hotkey IDs
164 165
    case ID_PREFERENCES_HOTKEY_SHOW_EDITOR:
        InstallHotkeyFrame( this, s_Eeschema_Hokeys_Descr );
charras's avatar
charras committed
166 167
        break;

168 169
    case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG:
        ExportHotkeyConfigToFile( s_Eeschema_Hokeys_Descr );
charras's avatar
charras committed
170 171
        break;

172 173
    case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG:
        ImportHotkeyConfigFromFile( s_Eeschema_Hokeys_Descr );
charras's avatar
charras committed
174 175 176 177 178 179 180 181
        break;

    case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST:
        // Display current hotkey list for LibEdit.
        DisplayHotkeyList( this, s_Libedit_Hokeys_Descr );
        break;

    default:
182
        DisplayError( this, wxT( "LIB_EDIT_FRAME::Process_Config error" ) );
charras's avatar
charras committed
183 184 185 186
    }
}


187
void SCH_EDIT_FRAME::OnColorConfig( wxCommandEvent& aEvent )
188 189 190 191 192 193 194
{
    DIALOG_COLOR_CONFIG dlg( this );

    dlg.ShowModal();
}


195
void SCH_EDIT_FRAME::InstallConfigFrame( wxCommandEvent& event )
196 197 198 199 200 201
{
    DIALOG_EESCHEMA_CONFIG CfgFrame( this, this );

    CfgFrame.ShowModal();
}

charras's avatar
charras committed
202

203
void SCH_EDIT_FRAME::Process_Config( wxCommandEvent& event )
charras's avatar
charras committed
204 205 206 207 208 209
{
    int        id = event.GetId();
    wxFileName fn;

    switch( id )
    {
CHARRAS's avatar
CHARRAS committed
210
    case ID_CONFIG_SAVE:
211
        SaveProjectSettings( false );
CHARRAS's avatar
CHARRAS committed
212 213 214 215
        break;

    case ID_CONFIG_READ:
    {
216
        fn = g_RootSheet->GetScreen()->GetFileName();
217 218 219 220 221 222 223
        fn.SetExt( ProjectFileExtension );

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

        if( dlg.ShowModal() == wxID_CANCEL )
CHARRAS's avatar
CHARRAS committed
224
            break;
225

226
        LoadProjectFile( dlg.GetPath(), true );
CHARRAS's avatar
CHARRAS committed
227
    }
228
    break;
CHARRAS's avatar
CHARRAS committed
229

230

231
    // Hotkey IDs
232 233
    case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG:
        ExportHotkeyConfigToFile( s_Eeschema_Hokeys_Descr );
CHARRAS's avatar
CHARRAS committed
234 235
        break;

236 237
    case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG:
        ImportHotkeyConfigFromFile( s_Eeschema_Hokeys_Descr );
CHARRAS's avatar
CHARRAS committed
238 239
        break;

240 241
    case ID_PREFERENCES_HOTKEY_SHOW_EDITOR:
        InstallHotkeyFrame( this, s_Eeschema_Hokeys_Descr );
CHARRAS's avatar
CHARRAS committed
242 243
        break;

244 245
    case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST:
        // Display current hotkey list for eeschema.
CHARRAS's avatar
CHARRAS committed
246 247 248 249
        DisplayHotkeyList( this, s_Schematic_Hokeys_Descr );
        break;

    default:
250
        DisplayError( this, wxT( "SCH_EDIT_FRAME::Process_Config error" ) );
CHARRAS's avatar
CHARRAS committed
251
    }
252 253 254
}


255
void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event )
256 257
{
    wxArrayString units;
258
    GRIDS grid_list;
259

260
    GetScreen()->GetGrids( grid_list );
261

262
    DIALOG_EESCHEMA_OPTIONS dlg( this );
263

264
    units.Add( GetUnitsLabel( INCHES ) );
265
    units.Add( GetUnitsLabel( MILLIMETRES ) );
266

267
    dlg.SetUnits( units, g_UserUnit );
268
    dlg.SetGridSizes( grid_list, GetScreen()->GetGridId() );
269 270 271
    dlg.SetBusWidth( GetDefaultBusThickness() );
    dlg.SetLineWidth( GetDefaultLineThickness() );
    dlg.SetTextSize( GetDefaultLabelSize() );
272 273 274
    dlg.SetRepeatHorizontal( g_RepeatStep.x );
    dlg.SetRepeatVertical( g_RepeatStep.y );
    dlg.SetRepeatLabel( g_RepeatDeltaLabel );
275
    dlg.SetAutoSaveInterval( GetAutoSaveInterval() / 60 );
276 277 278
    dlg.SetRefIdSeparator( LIB_COMPONENT::GetSubpartIdSeparator( ),
                           LIB_COMPONENT::GetSubpartFirstId() );

charras's avatar
charras committed
279
    dlg.SetShowGrid( IsGridVisible() );
280
    dlg.SetShowHiddenPins( m_showAllPins );
281
    dlg.SetEnableMiddleButtonPan( m_canvas->GetEnableMiddleButtonPan() );
282
    dlg.SetEnableZoomNoCenter( m_canvas->GetEnableZoomNoCenter() );
283
    dlg.SetMiddleButtonPanLimited( m_canvas->GetMiddleButtonPanLimited() );
284
    dlg.SetEnableAutoPan( m_canvas->GetEnableAutoPan() );
285
    dlg.SetEnableHVBusOrientation( GetForceHVLines() );
286 287 288 289 290
    dlg.SetShowPageLimits( g_ShowPageLimits );
    dlg.Layout();
    dlg.Fit();
    dlg.SetMinSize( dlg.GetSize() );

291 292 293 294
    const TEMPLATE_FIELDNAMES&  tfnames = m_TemplateFieldNames.GetTemplateFieldNames();

    for( unsigned i=0; i<tfnames.size(); ++i )
    {
295
        DBG(printf("dlg.SetFieldName(%d, '%s')\n", i, TO_UTF8( tfnames[i].m_Name) );)
296 297 298 299

        dlg.SetFieldName( i, tfnames[i].m_Name );
    }

300 301 302
    if( dlg.ShowModal() == wxID_CANCEL )
        return;

303
    g_UserUnit = (EDA_UNITS_T)dlg.GetUnitsSelection();
304

305
    GetScreen()->SetGrid( grid_list[ (size_t) dlg.GetGridSelection() ].m_Size );
306

307 308 309 310 311 312 313 314 315
    int sep, firstId;
    dlg.GetRefIdSeparator( sep, firstId);
    if( sep != (int)LIB_COMPONENT::GetSubpartIdSeparator() ||
        firstId != (int)LIB_COMPONENT::GetSubpartFirstId() )
    {
        LIB_COMPONENT::SetSubpartIdNotation( sep, firstId );
        SaveProjectSettings( true );
    }

316 317 318
    SetDefaultBusThickness( dlg.GetBusWidth() );
    SetDefaultLineThickness( dlg.GetLineWidth() );
    SetDefaultLabelSize( dlg.GetTextSize() );
319 320 321
    g_RepeatStep.x = dlg.GetRepeatHorizontal();
    g_RepeatStep.y = dlg.GetRepeatVertical();
    g_RepeatDeltaLabel = dlg.GetRepeatLabel();
322
    SetAutoSaveInterval( dlg.GetAutoSaveInterval() * 60 );
charras's avatar
charras committed
323
    SetGridVisibility( dlg.GetShowGrid() );
324
    m_showAllPins = dlg.GetShowHiddenPins();
325
    m_canvas->SetEnableMiddleButtonPan( dlg.GetEnableMiddleButtonPan() );
326
    m_canvas->SetEnableZoomNoCenter( dlg.GetEnableZoomNoCenter() );
327
    m_canvas->SetMiddleButtonPanLimited( dlg.GetMiddleButtonPanLimited() );
328
    m_canvas->SetEnableAutoPan( dlg.GetEnableAutoPan() );
329
    SetForceHVLines( dlg.GetEnableHVBusOrientation() );
330
    g_ShowPageLimits = dlg.GetShowPageLimits();
331 332 333 334 335 336 337

    wxString templateFieldName;

    // @todo this will change when the template field editor is redone to
    // look like the component field property editor, showing visibility and value also

    DeleteAllTemplateFieldNames();
338

339 340 341 342 343 344 345 346 347 348 349 350 351 352
    for( int i=0; i<8; ++i )    // no. fields in this dialog window
    {
        templateFieldName = dlg.GetFieldName( i );

        if( !templateFieldName.IsEmpty() )
        {
            TEMPLATE_FIELDNAME  fld( dlg.GetFieldName( i ) );

            // @todo set visibility and value also from a better editor

            AddTemplateFieldName( fld );
        }
    }

353
    m_canvas->Refresh( true );
354 355 356
}


357
PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetProjectFileParametersList()
358
{
359
    if( !m_projectFileParams.empty() )
360 361
        return m_projectFileParams;

362 363 364 365 366
    m_projectFileParams.push_back( new PARAM_CFG_FILENAME( wxT( "PageLayoutDescrFile" ),
                                        &BASE_SCREEN::m_PageLayoutDescrFileName ) );

    m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "SubpartIdSeparator" ),
                                        LIB_COMPONENT::SubpartIdSeparatorPtr(),
367
                                        0, 0, 126 ) );
368 369
    m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "SubpartFirstId" ),
                                        LIB_COMPONENT::SubpartFirstIdPtr(),
370
                                        'A', '1', 'z' ) );
371

372
    m_projectFileParams.push_back( new PARAM_CFG_FILENAME( wxT( "LibDir" ),
373
                                                           &m_userLibraryPath ) );
374
    m_projectFileParams.push_back( new PARAM_CFG_LIBNAME_LIST( wxT( "LibName" ),
375
                                                               &m_componentLibFiles,
376
                                                               GROUPLIB ) );
377 378
    m_projectFileParams.push_back( new PARAM_CFG_WXSTRING( wxT( "NetFmtName" ),
                                                         &m_netListFormat) );
379

380 381 382 383 384 385 386 387 388 389
    m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "RptD_X" ),
                                                      &g_RepeatStep.x,
                                                      0, -1000, +1000 ) );
    m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "RptD_Y" ),
                                                      &g_RepeatStep.y,
                                                      100, -1000, +1000 ) );
    m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "RptLab" ),
                                                      &g_RepeatDeltaLabel,
                                                      1, -10, +10 ) );
    m_projectFileParams.push_back( new PARAM_CFG_INT( wxT( "LabSize" ),
390 391
                                                      &m_defaultLabelSize,
                                                      DEFAULT_SIZE_TEXT, 5,
392
                                                      1000 ) );
393 394 395 396 397

    return m_projectFileParams;
}


398
bool SCH_EDIT_FRAME::LoadProjectFile( const wxString& aFileName, bool aForceReread )
399
{
400
    wxFileName              fn;
401
    bool                    IsRead = true;
402
    wxArrayString           liblist_tmp = m_componentLibFiles;
CHARRAS's avatar
CHARRAS committed
403

404
    if( aFileName.IsEmpty() )
405
        fn = g_RootSheet->GetScreen()->GetFileName();
CHARRAS's avatar
CHARRAS committed
406
    else
407
        fn = aFileName;
408

409
    m_componentLibFiles.Clear();
CHARRAS's avatar
CHARRAS committed
410

411 412 413 414
    /* Change the schematic file extension (.sch) to the project file
     * extension (.pro). */
    fn.SetExt( ProjectFileExtension );

415
    wxGetApp().RemoveLibraryPath( m_userLibraryPath );
416

417
    if( !wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP,
418
                                       GetProjectFileParametersList(),
419
                                       !aForceReread ) )
CHARRAS's avatar
CHARRAS committed
420
    {
421
        m_componentLibFiles = liblist_tmp;
422
        IsRead = false;
CHARRAS's avatar
CHARRAS committed
423 424
    }

425 426 427 428 429 430 431 432 433 434 435 436
    // Verify some values, because the config file can be edited by hand,
    // and have bad values:
    LIB_COMPONENT::SetSubpartIdNotation( LIB_COMPONENT::GetSubpartIdSeparator(),
                                         LIB_COMPONENT::GetSubpartFirstId() );

    // 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();
    pglayout.SetPageLayout(BASE_SCREEN::m_PageLayoutDescrFileName);

    // Load libraries.
437
    // User library path takes precedent over default library search paths.
438
    wxGetApp().InsertLibraryPath( m_userLibraryPath, 1 );
CHARRAS's avatar
CHARRAS committed
439

440
    /* If the list is void, force loading the library "power.lib" that is
441 442
     * the "standard" library for power symbols.
     */
443 444
    if( m_componentLibFiles.GetCount() == 0 )
        m_componentLibFiles.Add( wxT( "power" ) );
CHARRAS's avatar
CHARRAS committed
445

446
    LoadLibraries();
447
    GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId  );
CHARRAS's avatar
CHARRAS committed
448 449

    return IsRead;
450 451 452
}


453
void SCH_EDIT_FRAME::SaveProjectSettings( bool aAskForSave )
454
{
455 456
    wxFileName fn;

457
    fn = g_RootSheet->GetScreen()->GetFileName();  //ConfigFileName
458 459
    fn.SetExt( ProjectFileExtension );

460
    if( !IsWritable( fn ) )
CHARRAS's avatar
CHARRAS committed
461 462
        return;

463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
    if( aAskForSave )
    {
        wxFileDialog dlg( this, _( "Save Project File" ),
                          fn.GetPath(), fn.GetFullName(),
                          ProjectFileWildcard, wxFD_SAVE | wxFD_CHANGE_DIR );

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

        wxGetApp().WriteProjectConfig( dlg.GetPath(), GROUP,
                                       GetProjectFileParametersList() );
    }
    else
        wxGetApp().WriteProjectConfig( fn.GetFullPath(), GROUP,
                                       GetProjectFileParametersList() );
478 479
}

480
static const wxString DefaultBusWidthEntry( wxT( "DefaultBusWidth" ) );
481
static const wxString DefaultDrawLineWidthEntry( wxT( "DefaultDrawLineWidth" ) );
482
static const wxString ShowHiddenPinsEntry( wxT( "ShowHiddenPins" ) );
483
static const wxString HorzVertLinesOnlyEntry( wxT( "HorizVertLinesOnly" ) );
484 485 486 487 488 489 490 491
static const wxString PreviewFramePositionXEntry( wxT( "PreviewFramePositionX" ) );
static const wxString PreviewFramePositionYEntry( wxT( "PreviewFramePositionY" ) );
static const wxString PreviewFrameWidthEntry( wxT( "PreviewFrameWidth" ) );
static const wxString PreviewFrameHeightEntry( wxT( "PreviewFrameHeight" ) );
static const wxString PrintDialogPositionXEntry( wxT( "PrintDialogPositionX" ) );
static const wxString PrintDialogPositionYEntry( wxT( "PrintDialogPositionY" ) );
static const wxString PrintDialogWidthEntry( wxT( "PrintDialogWidth" ) );
static const wxString PrintDialogHeightEntry( wxT( "PrintDialogHeight" ) );
492 493 494 495 496 497 498 499 500
static const wxString FindDialogPositionXEntry( wxT( "FindDialogPositionX" ) );
static const wxString FindDialogPositionYEntry( wxT( "FindDialogPositionY" ) );
static const wxString FindDialogWidthEntry( wxT( "FindDialogWidth" ) );
static const wxString FindDialogHeightEntry( wxT( "FindDialogHeight" ) );
static const wxString FindReplaceFlagsEntry( wxT( "LastFindReplaceFlags" ) );
static const wxString FindStringEntry( wxT( "LastFindString" ) );
static const wxString ReplaceStringEntry( wxT( "LastReplaceString" ) );
static const wxString FindStringHistoryEntry( wxT( "FindStringHistoryList%d" ) );
static const wxString ReplaceStringHistoryEntry( wxT( "ReplaceStringHistoryList%d" ) );
501
static const wxString FieldNamesEntry( wxT( "FieldNames" ) );
502
static const wxString SimulatorCommandEntry( wxT( "SimCmdLine" ) );
503

504

505
PARAM_CFG_ARRAY& SCH_EDIT_FRAME::GetConfigurationSettings( void )
506
{
507
    if( !m_configSettings.empty() )
508 509
        return m_configSettings;

510 511
    m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "Units" ),
                                                   (int*)&g_UserUnit, MILLIMETRES ) );
512
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorWireEx" ),
513
                                                        &s_layerColor[LAYER_WIRE],
514
                                                        GREEN ) );
515
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorBusEx" ),
516
                                                        &s_layerColor[LAYER_BUS],
517
                                                        BLUE ) );
518
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorConnEx" ),
519
                                                        &s_layerColor[LAYER_JUNCTION],
520
                                                        GREEN ) );
521
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorLLabelEx" ),
522
                                                        &s_layerColor[LAYER_LOCLABEL],
523
                                                        BLACK ) );
524
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorHLabelEx" ),
525
                                                        &s_layerColor[LAYER_HIERLABEL],
526
                                                        BROWN ) );
527
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorGLabelEx" ),
528
                                                        &s_layerColor[LAYER_GLOBLABEL],
529
                                                        RED ) );
530
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorPinNumEx" ),
531
                                                        &s_layerColor[LAYER_PINNUM],
532
                                                        RED ) );
533
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorPinNameEx" ),
534
                                                        &s_layerColor[LAYER_PINNAM],
535
                                                        CYAN ) );
536
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorFieldEx" ),
537
                                                        &s_layerColor[LAYER_FIELDS],
538
                                                        MAGENTA ) );
539
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorReferenceEx" ),
540
                                                        &s_layerColor[LAYER_REFERENCEPART],
541
                                                        CYAN ) );
542
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorValueEx" ),
543
                                                        &s_layerColor[LAYER_VALUEPART],
544
                                                        CYAN ) );
545
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorNoteEx" ),
546
                                                        &s_layerColor[LAYER_NOTES],
547
                                                        LIGHTBLUE ) );
548
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorBodyEx" ),
549
                                                        &s_layerColor[LAYER_DEVICE],
550
                                                        RED ) );
551
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorBodyBgEx" ),
552
                                                        &s_layerColor[LAYER_DEVICE_BACKGROUND],
553
                                                        LIGHTYELLOW ) );
554
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorNetNameEx" ),
555
                                                        &s_layerColor[LAYER_NETNAM],
556
                                                        DARKGRAY ) );
557
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorPinEx" ),
558
                                                        &s_layerColor[LAYER_PIN],
559
                                                        RED ) );
560
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorSheetEx" ),
561
                                                        &s_layerColor[LAYER_SHEET],
562 563
                                                        MAGENTA ) );
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true,
564
                                                        wxT( "ColorSheetFileNameEx" ),
565
                                                        &s_layerColor[LAYER_SHEETFILENAME],
566
                                                        BROWN ) );
567
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorSheetNameEx" ),
568
                                                        &s_layerColor[LAYER_SHEETNAME],
569
                                                        CYAN ) );
570
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorSheetLabelEx" ),
571
                                                        &s_layerColor[LAYER_SHEETLABEL],
572
                                                        BROWN ) );
573
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorNoConnectEx" ),
574
                                                        &s_layerColor[LAYER_NOCONNECT],
575
                                                        BLUE ) );
576
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorErcWEx" ),
577
                                                        &s_layerColor[LAYER_ERC_WARN],
578
                                                        GREEN ) );
579
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorErcEEx" ),
580
                                                        &s_layerColor[LAYER_ERC_ERR],
581
                                                        RED ) );
582
    m_configSettings.push_back( new PARAM_CFG_SETCOLOR( true, wxT( "ColorGridEx" ),
583
                                                        &s_layerColor[LAYER_GRID],
584
                                                        DARKGRAY ) );
585
    m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "PrintMonochrome" ),
586
                                                    &m_printMonochrome, true ) );
587
    m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "PrintSheetReferenceAndTitleBlock" ),
588
                                                    &m_printSheetReference, true ) );
589

590
    return m_configSettings;
591 592 593
}


594
void SCH_EDIT_FRAME::LoadSettings()
595
{
596
    wxASSERT( wxGetApp().GetSettings() != NULL );
597

598 599
    long tmp;

600
    wxConfig* cfg = wxGetApp().GetSettings();
601

602
    EDA_DRAW_FRAME::LoadSettings();
603 604 605

    wxGetApp().ReadCurrentSetupValues( GetConfigurationSettings() );

606
    // This is required until someone gets rid of the global variable s_layerColor.
607
    m_GridColor = GetLayerColor( LAYER_GRID );
608

609 610
    SetDefaultBusThickness( cfg->Read( DefaultBusWidthEntry, 12l ) );
    SetDefaultLineThickness( cfg->Read( DefaultDrawLineWidthEntry, 6l ) );
611
    cfg->Read( ShowHiddenPinsEntry, &m_showAllPins, false );
612
    cfg->Read( HorzVertLinesOnlyEntry, &m_forceHVLines, true );
613

614
    // Load print preview window session settings.
615 616 617 618 619 620 621 622 623
    cfg->Read( PreviewFramePositionXEntry, &tmp, -1 );
    m_previewPosition.x = (int) tmp;
    cfg->Read( PreviewFramePositionYEntry, &tmp, -1 );
    m_previewPosition.y = (int) tmp;
    cfg->Read( PreviewFrameWidthEntry, &tmp, -1 );
    m_previewSize.SetWidth( (int) tmp );
    cfg->Read( PreviewFrameHeightEntry, &tmp, -1 );
    m_previewSize.SetHeight( (int) tmp );

624
    // Load print dialog session settings.
625 626 627 628 629 630 631 632
    cfg->Read( PrintDialogPositionXEntry, &tmp, -1 );
    m_printDialogPosition.x = (int) tmp;
    cfg->Read( PrintDialogPositionYEntry, &tmp, -1 );
    m_printDialogPosition.y = (int) tmp;
    cfg->Read( PrintDialogWidthEntry, &tmp, -1 );
    m_printDialogSize.SetWidth( (int) tmp );
    cfg->Read( PrintDialogHeightEntry, &tmp, -1 );
    m_printDialogSize.SetHeight( (int) tmp );
633

634
    // Load netlists options:
635
    cfg->Read( SimulatorCommandEntry, &m_simulatorCommand );
636

637
    // Load find dialog session setting.
638 639 640 641 642 643 644 645 646 647 648
    cfg->Read( FindDialogPositionXEntry, &tmp, -1 );
    m_findDialogPosition.x = (int) tmp;
    cfg->Read( FindDialogPositionYEntry, &tmp, -1 );
    m_findDialogPosition.y = (int) tmp;
    cfg->Read( FindDialogWidthEntry, &tmp, -1 );
    m_findDialogSize.SetWidth( (int) tmp );
    cfg->Read( FindDialogHeightEntry, &tmp, -1 );
    m_findDialogSize.SetHeight( (int) tmp );
    wxASSERT_MSG( m_findReplaceData,
                  wxT( "Find dialog data settings object not created. Bad programmer!" ) );
    cfg->Read( FindReplaceFlagsEntry, &tmp, (long) wxFR_DOWN );
649
    m_findReplaceData->SetFlags( (wxUint32) tmp & ~FR_REPLACE_ITEM_FOUND );
650 651 652
    m_findReplaceData->SetFindString( cfg->Read( FindStringEntry, wxEmptyString ) );
    m_findReplaceData->SetReplaceString( cfg->Read( ReplaceStringEntry, wxEmptyString ) );

653
    // Load the find and replace string history list.
654
    for( int i = 0; i < FR_HISTORY_LIST_CNT; ++i )
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
    {
        wxString tmpHistory;
        wxString entry;
        entry.Printf( FindStringHistoryEntry, i );
        tmpHistory = cfg->Read( entry, wxEmptyString );

        if( !tmpHistory.IsEmpty() )
            m_findStringHistoryList.Add( tmpHistory );

        entry.Printf( ReplaceStringHistoryEntry, i );
        tmpHistory = cfg->Read( entry, wxEmptyString );

        if( !tmpHistory.IsEmpty() )
            m_replaceStringHistoryList.Add( tmpHistory );
    }
670 671 672 673 674

    wxString templateFieldNames = cfg->Read( FieldNamesEntry, wxEmptyString );

    if( !templateFieldNames.IsEmpty() )
    {
675
        TEMPLATE_FIELDNAMES_LEXER  lexer( TO_UTF8( templateFieldNames ) );
676 677 678 679
        try
        {
            m_TemplateFieldNames.Parse( &lexer );
        }
Dick Hollenbeck's avatar
Dick Hollenbeck committed
680
        catch( IO_ERROR& e )
681 682
        {
            // @todo show error msg
683
            DBG( printf( "templatefieldnames parsing error: '%s'\n",
684
                       TO_UTF8( e.errorText ) ); )
685 686
        }
    }
687 688 689
}


690
void SCH_EDIT_FRAME::SaveSettings()
691
{
692
    wxASSERT( wxGetApp().GetSettings() != NULL );
693

694
    wxConfig* cfg = wxGetApp().GetSettings();
695

696
    EDA_DRAW_FRAME::SaveSettings();
697 698 699

    wxGetApp().SaveCurrentSetupValues( GetConfigurationSettings() );

700 701
    cfg->Write( DefaultBusWidthEntry, (long) GetDefaultBusThickness() );
    cfg->Write( DefaultDrawLineWidthEntry, (long) GetDefaultLineThickness() );
702
    cfg->Write( ShowHiddenPinsEntry, m_showAllPins );
703
    cfg->Write( HorzVertLinesOnlyEntry, GetForceHVLines() );
704

705
    // Save print preview window session settings.
706 707 708 709 710
    cfg->Write( PreviewFramePositionXEntry, m_previewPosition.x );
    cfg->Write( PreviewFramePositionYEntry, m_previewPosition.y );
    cfg->Write( PreviewFrameWidthEntry, m_previewSize.GetWidth() );
    cfg->Write( PreviewFrameHeightEntry, m_previewSize.GetHeight() );

711
    // Save print dialog session settings.
712 713 714 715
    cfg->Write( PrintDialogPositionXEntry, m_printDialogPosition.x );
    cfg->Write( PrintDialogPositionYEntry, m_printDialogPosition.y );
    cfg->Write( PrintDialogWidthEntry, m_printDialogSize.GetWidth() );
    cfg->Write( PrintDialogHeightEntry, m_printDialogSize.GetHeight() );
716

717
    // Save netlists options:
718
    cfg->Write( SimulatorCommandEntry, m_simulatorCommand );
719

720
    // Save find dialog session setting.
721 722 723 724 725 726
    cfg->Write( FindDialogPositionXEntry, m_findDialogPosition.x );
    cfg->Write( FindDialogPositionYEntry, m_findDialogPosition.y );
    cfg->Write( FindDialogWidthEntry, m_findDialogSize.GetWidth() );
    cfg->Write( FindDialogHeightEntry, m_findDialogSize.GetHeight() );
    wxASSERT_MSG( m_findReplaceData,
                  wxT( "Find dialog data settings object not created. Bad programmer!" ) );
727 728
    cfg->Write( FindReplaceFlagsEntry,
                (long) m_findReplaceData->GetFlags() & ~FR_REPLACE_ITEM_FOUND );
729 730 731
    cfg->Write( FindStringEntry, m_findReplaceData->GetFindString() );
    cfg->Write( ReplaceStringEntry, m_findReplaceData->GetReplaceString() );

732
    // Save the find and replace string history list.
733
    unsigned i;
734
    wxString tmpHistory;
735
    wxString entry;     // invoke constructor outside of any loops
736

737
    for( i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
738 739 740 741 742
    {
        entry.Printf( FindStringHistoryEntry, i );
        cfg->Write( entry, m_findStringHistoryList[ i ] );
    }

743
    for( i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
744 745 746 747
    {
        entry.Printf( ReplaceStringHistoryEntry, i );
        cfg->Write( entry, m_replaceStringHistoryList[ i ] );
    }
748 749

    // Save template fieldnames
750
    STRING_FORMATTER sf;
751 752 753

    m_TemplateFieldNames.Format( &sf, 0 );

754
    DBG(printf("saving formatted template fieldnames:'%s'\n", sf.GetString().c_str() );)
Dick Hollenbeck's avatar
Dick Hollenbeck committed
755

756
    wxString record = FROM_UTF8( sf.GetString().c_str() );
757 758 759 760
    record.Replace( wxT("\n"), wxT(""), true );   // strip all newlines
    record.Replace( wxT("  "), wxT(" "), true );  // double space to single

    cfg->Write( FieldNamesEntry, record );
761
}