gerbview_frame.cpp 24.1 KB
Newer Older
1 2 3
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
4 5
 * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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
 */

25 26 27
/**
 * @file gerbview_frame.cpp
 */
plyatov's avatar
plyatov committed
28

29 30 31 32 33 34
#include <fctsys.h>
#include <appl_wxstruct.h>
#include <wxstruct.h>
#include <class_drawpanel.h>
#include <build_version.h>
#include <macros.h>
35
#include <trigo.h>
36
#include <base_units.h>
37 38
#include <colors_selection.h>
#include <class_gbr_layer_box_selector.h>
39
#include <msgpanel.h>
40

41 42 43 44 45 46 47 48 49
#include <gerbview.h>
#include <class_gerber_draw_item.h>
#include <pcbplot.h>
#include <gerbview_id.h>
#include <hotkeys.h>
#include <class_GERBER.h>
#include <dialog_helpers.h>
#include <class_DCodeSelectionbox.h>
#include <class_gerbview_layer_widget.h>
50
#include <class_gbr_screen.h>
51

plyatov's avatar
plyatov committed
52

53
// Config keywords
54
static const wxString   cfgShowPageSizeOption( wxT( "PageSizeOpt" ) );
55
static const wxString   cfgShowDCodes( wxT( "ShowDCodesOpt" ) );
56
static const wxString   cfgShowNegativeObjects( wxT( "ShowNegativeObjectsOpt" ) );
57
static const wxString   cfgShowBorderAndTitleBlock( wxT( "ShowBorderAndTitleBlock" ) );
58

59

60 61 62
/*************************************/
/* class GERBVIEW_FRAME for GerbView */
/*************************************/
plyatov's avatar
plyatov committed
63

64 65 66 67 68 69 70
#define GERBVIEW_FRAME_NAME wxT( "GerberFrame" )

GERBVIEW_FRAME::GERBVIEW_FRAME( wxWindow* aParent, const wxString& aTitle,
                                const wxPoint& aPosition, const wxSize& aSize,
                                long aStyle ) :
    EDA_DRAW_FRAME( aParent, GERBER_FRAME_TYPE, aTitle, aPosition, aSize,
                    aStyle, GERBVIEW_FRAME_NAME )
plyatov's avatar
plyatov committed
71
{
72
    m_colorsSettings = &g_ColorsSettings;
73
    m_gerberLayout = NULL;
74

75
    m_FrameName = GERBVIEW_FRAME_NAME;
charras's avatar
charras committed
76
    m_show_layer_manager_tools = true;
77

78
    m_showAxis = true;                      // true to show X and Y axis on screen
79 80
    m_showBorderAndTitleBlock   = false;    // true for reference drawings.
    m_HotkeysZoomAndGridList    = s_Gerbview_Hokeys_Descr;
81 82 83
    m_SelLayerBox   = NULL;
    m_DCodeSelector = NULL;
    m_displayMode   = 0;
84
    m_drillFileHistory.SetBaseId( ID_GERBVIEW_DRILL_FILE1 );
85

86
    if( m_canvas )
87
        m_canvas->SetEnableBlockCommands( true );
88 89

    // Give an icon
90 91 92
    wxIcon icon;
    icon.CopyFromBitmap( KiBitmap( icon_gerbview_xpm ) );
    SetIcon( icon );
93

94
    SetLayout( new GBR_LAYOUT() );
95

96
    SetVisibleLayers( FULL_LAYERS );     // All 32 layers visible.
97

98
    SetScreen( new GBR_SCREEN( GetGerberLayout()->GetPageSettings().GetSizeIU() ) );
99

100 101 102 103
    // Create the PCB_LAYER_WIDGET *after* SetLayout():
    wxFont  font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
    int     pointSize       = font.GetPointSize();
    int     screenHeight    = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
104

charras's avatar
charras committed
105 106
    if( screenHeight <= 900 )
        pointSize = (pointSize * 8) / 10;
107

108
    m_LayersManager = new GERBER_LAYER_WIDGET( this, m_canvas, pointSize );
charras's avatar
charras committed
109 110 111 112

    // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
    // initialize parameters in m_LayersManager
    LoadSettings();
113
    SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
114

115 116 117 118
    if( m_LastGridSizeId < 0 )
        m_LastGridSizeId = 0;
    if( m_LastGridSizeId > ID_POPUP_GRID_LEVEL_0_0_1MM-ID_POPUP_GRID_LEVEL_1000 )
        m_LastGridSizeId = ID_POPUP_GRID_LEVEL_0_0_1MM-ID_POPUP_GRID_LEVEL_1000;
119
    GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId  );
120

121 122 123
    ReCreateMenuBar();
    ReCreateHToolbar();
    ReCreateOptToolbar();
124 125

    m_auimgr.SetManagedWindow( this );
126

127
    EDA_PANEINFO    horiz;
128 129
    horiz.HorizontalToolbarPane();

130
    EDA_PANEINFO    vert;
131 132
    vert.VerticalToolbarPane();

133
    EDA_PANEINFO    mesg;
134 135
    mesg.MessageToolbarPane();

136
    EDA_PANEINFO    lyrs;
137 138 139
    lyrs.LayersToolbarPane();
    lyrs.MinSize( m_LayersManager->GetBestSize() );
    lyrs.BestSize( m_LayersManager->GetBestSize() );
charras's avatar
charras committed
140
    lyrs.Caption( _( "Visibles" ) );
141

charras's avatar
charras committed
142

143 144 145
    if( m_mainToolBar )
        m_auimgr.AddPane( m_mainToolBar,
                          wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top().Row( 0 ) );
146

147 148 149
    if( m_drawToolBar )
        m_auimgr.AddPane( m_drawToolBar,
                          wxAuiPaneInfo( vert ).Name( wxT( "m_drawToolBar" ) ).Right().Row( 1 ) );
charras's avatar
charras committed
150

151
    m_auimgr.AddPane( m_LayersManager,
152
                      lyrs.Name( wxT( "m_LayersManagerToolBar" ) ).Right().Layer( 0 ) );
153

154 155 156
    if( m_optionsToolBar )
        m_auimgr.AddPane( m_optionsToolBar,
                          wxAuiPaneInfo( vert ).Name( wxT( "m_optionsToolBar" ) ).Left() );
157

158 159
    if( m_canvas )
        m_auimgr.AddPane( m_canvas,
160
                          wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() );
161

162 163
    if( m_messagePanel )
        m_auimgr.AddPane( m_messagePanel,
164
                          wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer( 10 ) );
165

166 167
    ReFillLayerWidget();                // this is near end because contents establish size
    m_LayersManager->ReFillRender();    // Update colors in Render after the config is read
168
    m_auimgr.Update();
plyatov's avatar
plyatov committed
169 170 171
}


172
GERBVIEW_FRAME::~GERBVIEW_FRAME()
plyatov's avatar
plyatov committed
173
{
174
    wxGetApp().SaveCurrentSetupValues( m_configSettings );
plyatov's avatar
plyatov committed
175 176 177
}


178
void GERBVIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
plyatov's avatar
plyatov committed
179
{
180 181
    SaveSettings();
    Destroy();
plyatov's avatar
plyatov committed
182 183
}

184

185 186
double GERBVIEW_FRAME::BestZoom()
{
187
    GERBER_DRAW_ITEM* item = GetGerberLayout()->m_Drawings;
188

189
    // gives a minimal value to zoom, if no item in list
190 191
    if( item == NULL  )
        return ZOOM_FACTOR( 350.0 );
192

193
    EDA_RECT bbox = GetGerberLayout()->ComputeBoundingBox();
194

195
    wxSize  size = m_canvas->GetClientSize();
196

197 198
    double  x   = (double) bbox.GetWidth() / (double) size.x;
    double  y   = (double) bbox.GetHeight() / (double) size.y;
199
    SetScrollCenterPosition( bbox.Centre() );
200

201
    double  best_zoom = std::max( x, y );
202 203 204 205
    return best_zoom;
}


206
void GERBVIEW_FRAME::LoadSettings()
207
{
208
    wxConfig* config = wxGetApp().GetSettings();
209 210 211 212

    if( config == NULL )
        return;

213
    EDA_DRAW_FRAME::LoadSettings();
214 215 216

    wxGetApp().ReadCurrentSetupValues( GetConfigurationSettings() );

217
    PAGE_INFO pageInfo( wxT( "GERBER" ) );
218

219
    config->Read( cfgShowBorderAndTitleBlock, &m_showBorderAndTitleBlock, false );
220

221 222
    if( m_showBorderAndTitleBlock )
    {
223
        wxString pageType;
224 225 226 227 228

        config->Read( cfgShowPageSizeOption, &pageType, wxT( "GERBER" ) );

        pageInfo.SetType( pageType );
    }
229

230
    SetPageSettings( pageInfo );
231

232
    GetScreen()->InitDataPoints( pageInfo.GetSizeIU() );
233

234 235
    bool tmp;
    config->Read( cfgShowDCodes, &tmp, true );
236
    SetElementVisibility( DCODES_VISIBLE, tmp );
237 238
    config->Read( cfgShowNegativeObjects, &tmp, false );
    SetElementVisibility( NEGATIVE_OBJECTS_VISIBLE, tmp );
239 240 241

    // because we have 2 file historues, we must read this one
    // using a specific path
242
    config->SetPath( wxT( "drl_files" ) );
243
    m_drillFileHistory.Load( *config );
244
    config->SetPath( wxT( ".." ) );
245 246 247 248

    // WxWidgets 2.9.1 seems call setlocale( LC_NUMERIC, "" )
    // when reading doubles in config,
    // but forget to back to current locale. So we call SetLocaleTo_Default
249
    SetLocaleTo_Default();
250 251
}

252

253
void GERBVIEW_FRAME::SaveSettings()
254
{
255
    wxConfig* config = wxGetApp().GetSettings();
256 257 258 259

    if( config == NULL )
        return;

260
    EDA_DRAW_FRAME::SaveSettings();
261

262 263
    wxGetApp().SaveCurrentSetupValues( GetConfigurationSettings() );

264 265 266
    config->Write( cfgShowPageSizeOption, GetPageSettings().GetType() );
    config->Write( cfgShowBorderAndTitleBlock, m_showBorderAndTitleBlock );
    config->Write( cfgShowDCodes, IsElementVisible( DCODES_VISIBLE ) );
267 268
    config->Write( cfgShowNegativeObjects,
                   IsElementVisible( NEGATIVE_OBJECTS_VISIBLE ) );
jean-pierre charras's avatar
jean-pierre charras committed
269

270 271
    // Save the drill file history list.
    // Because we have 2 file histories, we must save this one
272
    // in a specific path
273
    config->SetPath( wxT( "drl_files" ) );
274
    m_drillFileHistory.Save( *config );
275
    config->SetPath( wxT( ".." ) );
charras's avatar
charras committed
276 277 278
}


279
void GERBVIEW_FRAME::ReFillLayerWidget()
charras's avatar
charras committed
280 281 282
{
    m_LayersManager->ReFill();

283
    wxAuiPaneInfo&  lyrs = m_auimgr.GetPane( m_LayersManager );
charras's avatar
charras committed
284

285
    wxSize          bestz = m_LayersManager->GetBestSize();
charras's avatar
charras committed
286 287 288 289 290 291 292 293 294

    lyrs.MinSize( bestz );
    lyrs.BestSize( bestz );
    lyrs.FloatingSize( bestz );

    if( lyrs.IsDocked() )
        m_auimgr.Update();
    else
        m_LayersManager->SetSize( bestz );
295

296
    syncLayerWidget();
charras's avatar
charras committed
297 298 299 300 301
}

/**
 * Function SetElementVisibility
 * changes the visibility of an element category
302
 * @param aItemIdVisible is an item id from the enum GERBER_VISIBLE_ID
charras's avatar
charras committed
303 304
 * @param aNewState = The new visibility state of the element category
 */
305 306
void GERBVIEW_FRAME::SetElementVisibility( GERBER_VISIBLE_ID aItemIdVisible,
                                           bool aNewState )
charras's avatar
charras committed
307
{
308 309 310 311 312 313
    switch( aItemIdVisible )
    {
    case DCODES_VISIBLE:
        m_DisplayOptions.m_DisplayDCodes = aNewState;
        break;

314 315 316 317
    case NEGATIVE_OBJECTS_VISIBLE:
        m_DisplayOptions.m_DisplayNegativeObjects = aNewState;
        break;

318 319 320 321 322 323 324 325
    case GERBER_GRID_VISIBLE:
        SetGridVisibility( aNewState );
        break;

    default:
        wxLogDebug( wxT( "GERBVIEW_FRAME::SetElementVisibility(): bad arg %d" ), aItemIdVisible );
    }
    m_LayersManager->SetRenderState( aItemIdVisible, aNewState );
326
}
327 328


329
LAYER_NUM GERBVIEW_FRAME::getNextAvailableLayer( LAYER_NUM aLayer ) const
330
{
331
    LAYER_NUM layer = aLayer;
332

333
    for( LAYER_NUM i = FIRST_LAYER; i < NB_GERBER_LAYERS; ++i )
334 335 336 337 338 339
    {
        GERBER_IMAGE* gerber = g_GERBER_List[ layer ];

        if( gerber == NULL || gerber->m_FileName.IsEmpty() )
            return layer;

340
        ++layer;
341

342 343
        if( layer >= NB_GERBER_LAYERS )
            layer = FIRST_LAYER;
344 345 346 347 348 349
    }

    return NO_AVAILABLE_LAYERS;
}


350
void GERBVIEW_FRAME::syncLayerWidget()
351 352
{
    m_LayersManager->SelectLayer( getActiveLayer() );
353
    UpdateTitleAndInfo();
354 355
}

356

357 358 359 360 361 362
/**
 * Function syncLayerBox
 * updates the currently "selected" layer within m_SelLayerBox
 * The currently active layer, as defined by the return value of
 * getActiveLayer().  And updates the colored icon in the toolbar.
 */
363
void GERBVIEW_FRAME::syncLayerBox()
364 365
{
    m_SelLayerBox->SetSelection( getActiveLayer() );
366 367
    int             dcodeSelected = -1;
    GERBER_IMAGE*   gerber = g_GERBER_List[getActiveLayer()];
368

369 370
    if( gerber )
        dcodeSelected = gerber->m_Selected_Tool;
371

372 373 374 375 376
    if( m_DCodeSelector )
    {
        m_DCodeSelector->SetDCodeSelection( dcodeSelected );
        m_DCodeSelector->Enable( gerber != NULL );
    }
377

378
    UpdateTitleAndInfo();
379 380
}

381
void GERBVIEW_FRAME::Liste_D_Codes()
382
{
383 384 385 386
    int             ii, jj;
    D_CODE*         pt_D_code;
    wxString        Line;
    wxArrayString   list;
387 388
    double          scale = g_UserUnit == INCHES ? IU_PER_MILS * 1000 :
                            IU_PER_MM;
389
    LAYER_NUM       curr_layer = getActiveLayer();
390

391
    for( LAYER_NUM layer = FIRST_LAYER; layer < NB_LAYERS; ++layer )
392
    {
393
        GERBER_IMAGE* gerber = g_GERBER_List[layer];
394

395 396 397 398 399 400 401 402 403 404
        if( gerber == NULL )
            continue;

        if( gerber->ReturnUsedDcodeNumber() == 0 )
            continue;

        if( layer == curr_layer )
            Line.Printf( wxT( "*** Active layer (%2.2d) ***" ), layer + 1 );
        else
            Line.Printf( wxT( "*** layer %2.2d  ***" ), layer + 1 );
405

406
        list.Add( Line );
407

408
        const char* units = g_UserUnit == INCHES ? "\"" : "mm";
409 410 411
        for( ii = 0, jj = 1; ii < TOOLS_MAX_COUNT; ii++ )
        {
            pt_D_code = gerber->GetDCODE( ii + FIRST_DCODE, false );
412

413 414 415 416 417 418
            if( pt_D_code == NULL )
                continue;

            if( !pt_D_code->m_InUse && !pt_D_code->m_Defined )
                continue;

419
            Line.Printf( wxT( "tool %2.2d:   D%2.2d   V %.4f %s  H %.4f %s   %s  " ),
420 421
                         jj,
                         pt_D_code->m_Num_Dcode,
422 423
                         pt_D_code->m_Size.y / scale, units,
                         pt_D_code->m_Size.x / scale, units,
424 425 426 427
                         D_CODE::ShowApertureType( pt_D_code->m_Shape )
                         );

            if( !pt_D_code->m_Defined )
428
                Line += wxT( "(not used)" );
429 430

            if( !pt_D_code->m_InUse )
431
                Line += wxT( "(in use)" );
432

433
            list.Add( Line );
434 435 436 437
            jj++;
        }
    }

438
#if wxCHECK_VERSION( 2, 9, 4 )
439 440
    wxSingleChoiceDialog    dlg( this, wxEmptyString, _( "D Codes" ), list, (void**) NULL,
                                 wxCHOICEDLG_STYLE & ~wxCANCEL );
441
#else
442 443
    wxSingleChoiceDialog    dlg( this, wxEmptyString, _( "D Codes" ), list, (char**) NULL,
                                 wxCHOICEDLG_STYLE & ~wxCANCEL );
444
#endif
445

446
    dlg.ShowModal();
447
}
448

449

450
/*
451
 * Function UpdateTitleAndInfo
452
 * displays the short filename (if exists) of the selected layer
453
 *  on the caption of the main GerbView window
454 455 456 457
 * displays image name and the last layer name (found in the gerber file: LN <name> command)
 *  in the status bar
 * Note layer name can change when reading a gerber file, and the layer name is the last found.
 * So, show the layer name is not very useful, and can be seen as a debug feature.
458
 */
459
void GERBVIEW_FRAME::UpdateTitleAndInfo()
460
{
461 462
    GERBER_IMAGE*   gerber = g_GERBER_List[ getActiveLayer() ];
    wxString        text;
463

464 465 466
    // Display the gerber filename
    if( gerber == NULL )
    {
467
        text.Printf( wxT( "GerbView %s" ), GetChars( GetBuildVersion() ) );
468
        SetTitle( text );
469
        SetStatusText( wxEmptyString, 0 );
470
        text.Printf( _( "Layer %d not in use" ), getActiveLayer() + 1 );
jean-pierre charras's avatar
jean-pierre charras committed
471
        m_TextInfo->SetValue( text );
472
        ClearMsgPanel();
473 474 475 476 477
        return;
    }

    text = _( "File:" );
    text << wxT( " " ) << gerber->m_FileName;
478
    SetTitle( text );
479

480
    gerber->DisplayImageInfo();
481

482
    // Display Image Name and Layer Name (from the current gerber data):
483
    text.Printf( _( "Image name: '%s'  Layer name: '%s'" ),
484 485
                 GetChars( gerber->m_ImageName ),
                 GetChars( gerber->GetLayerParams().m_LayerName ) );
486 487
    SetStatusText( text, 0 );

488
    // Display data format like fmt in X3.4Y3.4 no LZ or fmt mm X2.3 Y3.5 no TZ in main toolbar
489
    text.Printf( wxT( "fmt: %s X%d.%d Y%d.%d no %cZ" ),
490 491 492 493
                 gerber->m_GerbMetric ? wxT( "mm" ) : wxT( "in" ),
                 gerber->m_FmtLen.x - gerber->m_FmtScale.x, gerber->m_FmtScale.x,
                 gerber->m_FmtLen.y - gerber->m_FmtScale.y, gerber->m_FmtScale.y,
                 gerber->m_NoTrailingZeros ? 'T' : 'L' );
494 495 496 497

    m_TextInfo->SetValue( text );
}

498 499
/*
 * Function IsElementVisible
500 501 502
 * tests whether a given element category is visible
 * aItemIdVisible is an item id from the enum GERBER_VISIBLE_ID
 * return true if the element is visible.
503
 */
504
bool GERBVIEW_FRAME::IsElementVisible( GERBER_VISIBLE_ID aItemIdVisible ) const
505 506 507 508 509 510 511
{
    switch( aItemIdVisible )
    {
    case DCODES_VISIBLE:
        return m_DisplayOptions.m_DisplayDCodes;
        break;

512 513 514 515
    case NEGATIVE_OBJECTS_VISIBLE:
        return m_DisplayOptions.m_DisplayNegativeObjects;
        break;

516 517 518 519 520
    case GERBER_GRID_VISIBLE:
        return IsGridVisible();
        break;

    default:
521
        wxLogDebug( wxT( "GERBVIEW_FRAME::IsElementVisible(): bad arg %d" ), aItemIdVisible );
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
    }

    return true;
}


/**
 * Function SetVisibleAlls
 * Set the status of all layers to VISIBLE
 */
void GERBVIEW_FRAME::SetVisibleAlls()
{
}

/**
 * Function GetVisibleLayers
 * is a proxy function that calls the correspondent function in m_BoardSettings
 * Returns a bit-mask of all the layers that are visible
 * @return int - the visible layers in bit-mapped form.
 */
542
LAYER_MSK GERBVIEW_FRAME::GetVisibleLayers() const
543
{
544
    return FULL_LAYERS;    // TODO
545 546 547 548 549 550 551 552 553
}


/**
 * Function SetVisibleLayers
 * is a proxy function that calls the correspondent function in m_BoardSettings
 * changes the bit-mask of visible layers
 * @param aLayerMask = The new bit-mask of visible layers
 */
554
void GERBVIEW_FRAME::SetVisibleLayers( LAYER_MSK aLayerMask )
555
{
556
    GetGerberLayout()->SetVisibleLayers( aLayerMask );
557 558 559 560 561 562
}


/**
 * Function IsLayerVisible
 * tests whether a given layer is visible
563
 * @param aLayer = The layer to be tested
564 565
 * @return bool - true if the layer is visible.
 */
566
bool GERBVIEW_FRAME::IsLayerVisible( LAYER_NUM aLayer ) const
567 568
{
    if( ! m_DisplayOptions.m_IsPrinting )
569
        return m_LayersManager->IsLayerVisible( aLayer );
570
    else
571
        return GetGerberLayout()->IsLayerVisible( aLayer );
572 573 574 575 576 577 578 579
}


/**
 * Function GetVisibleElementColor
 * returns the color of a pcb visible element.
 * @see enum PCB_VISIBLE
 */
580
EDA_COLOR_T GERBVIEW_FRAME::GetVisibleElementColor( GERBER_VISIBLE_ID aItemIdVisible ) const
581
{
582
    EDA_COLOR_T color = UNSPECIFIED_COLOR;
583 584 585

    switch( aItemIdVisible )
    {
586
    case NEGATIVE_OBJECTS_VISIBLE:
587 588 589 590 591 592 593 594 595
    case DCODES_VISIBLE:
        color = m_colorsSettings->GetItemColor( aItemIdVisible );
        break;

    case GERBER_GRID_VISIBLE:
        color = GetGridColor();
        break;

    default:
596 597
        wxLogDebug( wxT( "GERBVIEW_FRAME::GetVisibleElementColor(): bad arg %d" ),
                    (int)aItemIdVisible );
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
    }

    return color;
}

/*
 * Virtual from EDA_DRAW_FRAME
 */
void GERBVIEW_FRAME::SetGridVisibility( bool aVisible )
{
    EDA_DRAW_FRAME::SetGridVisibility( aVisible );
    m_LayersManager->SetRenderState( GERBER_GRID_VISIBLE, aVisible );
}


613 614
void GERBVIEW_FRAME::SetVisibleElementColor( GERBER_VISIBLE_ID aItemIdVisible,
                                             EDA_COLOR_T aColor )
615 616 617
{
    switch( aItemIdVisible )
    {
618
    case NEGATIVE_OBJECTS_VISIBLE:
619 620 621 622 623 624 625 626 627 628
    case DCODES_VISIBLE:
        m_colorsSettings->SetItemColor( aItemIdVisible, aColor );
        break;

    case GERBER_GRID_VISIBLE:
        SetGridColor( aColor );
        m_colorsSettings->SetItemColor( aItemIdVisible, aColor );
        break;

    default:
629 630
        wxLogDebug( wxT( "GERBVIEW_FRAME::SetVisibleElementColor(): bad arg %d" ),
                    (int) aItemIdVisible );
631 632 633
    }
}

634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
/*
 * Function GetNegativeItemsColor
 * returns the color of negative items.
 * This is usually the background color, but can be an other color
 * in order to see negative objects
 * therefore returns the background color if negative items not visible
 * and the color selection of negative items if they are visible
 */
EDA_COLOR_T GERBVIEW_FRAME::GetNegativeItemsColor() const
{
    if( IsElementVisible( NEGATIVE_OBJECTS_VISIBLE ) )
        return GetVisibleElementColor( NEGATIVE_OBJECTS_VISIBLE );
    else
        return g_DrawBgColor;
}
649

650 651

/*
652
 * Function GetLayerColor
653
 * gets a layer color for any valid layer.
654
 */
655
EDA_COLOR_T GERBVIEW_FRAME::GetLayerColor( LAYER_NUM aLayer ) const
656 657 658 659 660 661 662
{
    return m_colorsSettings->GetLayerColor( aLayer );
}


/**
 * Function SetLayerColor
663
 * changes a layer color for any valid layer.
664
 */
665
void GERBVIEW_FRAME::SetLayerColor( LAYER_NUM aLayer, EDA_COLOR_T aColor )
666 667 668 669 670 671 672 673 674
{
    m_colorsSettings->SetLayerColor( aLayer, aColor );
}


/**
 * Function getActiveLayer
 * returns the active layer
 */
675
LAYER_NUM GERBVIEW_FRAME::getActiveLayer()
676 677 678 679 680 681 682 683 684 685
{
    return ( (GBR_SCREEN*) GetScreen() )->m_Active_Layer;
}


/**
 * Function setActiveLayer
 * will change the currently active layer to \a aLayer and also
 * update the PCB_LAYER_WIDGET.
 */
686
void GERBVIEW_FRAME::setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate )
687 688 689 690 691 692 693 694 695 696
{
    ( (GBR_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;

    if( doLayerWidgetUpdate )
        m_LayersManager->SelectLayer( getActiveLayer() );
}


void GERBVIEW_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
{
697 698
    wxASSERT( m_gerberLayout );
    m_gerberLayout->SetPageSettings( aPageSettings );
699 700 701 702 703 704 705 706

    if( GetScreen() )
        GetScreen()->InitDataPoints( aPageSettings.GetSizeIU() );
}


const PAGE_INFO& GERBVIEW_FRAME::GetPageSettings() const
{
707 708
    wxASSERT( m_gerberLayout );
    return m_gerberLayout->GetPageSettings();
709 710 711 712 713
}


const wxSize GERBVIEW_FRAME::GetPageSizeIU() const
{
714
    wxASSERT( m_gerberLayout );
715 716 717 718

    // this function is only needed because EDA_DRAW_FRAME is not compiled
    // with either -DPCBNEW or -DEESCHEMA, so the virtual is used to route
    // into an application specific source file.
719
    return m_gerberLayout->GetPageSettings().GetSizeIU();
720 721 722 723 724
}


const TITLE_BLOCK& GERBVIEW_FRAME::GetTitleBlock() const
{
725 726
    wxASSERT( m_gerberLayout );
    return m_gerberLayout->GetTitleBlock();
727 728 729 730 731
}


void GERBVIEW_FRAME::SetTitleBlock( const TITLE_BLOCK& aTitleBlock )
{
732 733
    wxASSERT( m_gerberLayout );
    m_gerberLayout->SetTitleBlock( aTitleBlock );
734 735 736
}


737
const wxPoint& GERBVIEW_FRAME::GetAuxOrigin() const
738
{
739
    wxASSERT( m_gerberLayout );
740
    return m_gerberLayout->GetAuxOrigin();
741 742 743
}


744
void GERBVIEW_FRAME::SetAuxOrigin( const wxPoint& aPosition )
745
{
746
    wxASSERT( m_gerberLayout );
747
    m_gerberLayout->SetAuxOrigin( aPosition );
748 749
}

750

751 752 753 754 755 756 757
void GERBVIEW_FRAME::SetCurItem( GERBER_DRAW_ITEM* aItem, bool aDisplayInfo )
{
    GetScreen()->SetCurItem( aItem );

    if( aItem )
    {
        if( aDisplayInfo )
758 759 760 761 762
        {
            MSG_PANEL_ITEMS items;
            aItem->GetMsgPanelInfo( items );
            SetMsgPanel( items );
        }
763 764
    }
    else
765
    {
766
        EraseMsgBox();
767
    }
768 769
}

770

771
/*
772
 * Function GetGerberLayoutBoundingBox
773 774
 * returns the bounding box containing all gerber items.
 */
775
EDA_RECT GERBVIEW_FRAME::GetGerberLayoutBoundingBox()
776
{
777 778
    GetGerberLayout()->ComputeBoundingBox();
    return GetGerberLayout()->GetBoundingBox();
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
}

/*
 * Update the status bar information.
 */
void GERBVIEW_FRAME::UpdateStatusBar()
{
    EDA_DRAW_FRAME::UpdateStatusBar();

    GBR_SCREEN* screen = (GBR_SCREEN*) GetScreen();

    if( !screen )
        return;

    int dx;
    int dy;
    double dXpos;
    double dYpos;
    wxString line;
    wxString locformatter;

    if( m_DisplayOptions.m_DisplayPolarCood )  // display relative polar coordinates
    {
        double       theta, ro;

804 805
        dx = GetCrossHairPosition().x - screen->m_O_Curseur.x;
        dy = GetCrossHairPosition().y - screen->m_O_Curseur.y;
806

807 808
        // atan2 in the 0,0 case returns 0
        theta = RAD2DEG( atan2( -dy, dx ) );
809

810
        ro = hypot( dx, dy );
811 812 813 814
        wxString formatter;
        switch( g_UserUnit )
        {
        case INCHES:
815
            formatter = wxT( "Ro %.6f Th %.1f" );
816 817 818
            break;

        case MILLIMETRES:
819
            formatter = wxT( "Ro %.5f Th %.1f" );
820 821 822 823 824 825 826 827 828 829 830 831 832
            break;

        case UNSCALED_UNITS:
            formatter = wxT( "Ro %f Th %f" );
            break;
        }

        line.Printf( formatter, To_User_Unit( g_UserUnit, ro ), theta );

        SetStatusText( line, 3 );
    }

    // Display absolute coordinates:
833 834
    dXpos = To_User_Unit( g_UserUnit, GetCrossHairPosition().x );
    dYpos = To_User_Unit( g_UserUnit, GetCrossHairPosition().y );
835 836 837 838 839 840

    wxString absformatter;

    switch( g_UserUnit )
    {
    case INCHES:
841 842
        absformatter = wxT( "X %.6f  Y %.6f" );
        locformatter = wxT( "dx %.6f  dy %.6f  d %.6f" );
843 844 845
        break;

    case MILLIMETRES:
846 847
        absformatter = wxT( "X %.5f  Y %.5f" );
        locformatter = wxT( "dx %.5f  dy %.5f  d %.5f" );
848 849 850 851 852 853 854 855 856 857 858 859 860 861
        break;

    case UNSCALED_UNITS:
        absformatter = wxT( "X %f  Y %f" );
        locformatter = wxT( "dx %f  dy %f  d %f" );
        break;
    }

    line.Printf( absformatter, dXpos, dYpos );
    SetStatusText( line, 2 );

    if( !m_DisplayOptions.m_DisplayPolarCood )  // display relative cartesian coordinates
    {
        // Display relative coordinates:
862 863
        dx = GetCrossHairPosition().x - screen->m_O_Curseur.x;
        dy = GetCrossHairPosition().y - screen->m_O_Curseur.y;
864 865 866 867
        dXpos = To_User_Unit( g_UserUnit, dx );
        dYpos = To_User_Unit( g_UserUnit, dy );

        // We already decided the formatter above
868
        line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );
869 870 871 872
        SetStatusText( line, 3 );
    }
}