pcb_painter.cpp 27.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2013 CERN
 * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
 * @author Maciej Suminski <maciej.suminski@cern.ch>
 *
 * 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
 */

26
#include <class_board.h>
27 28 29 30 31 32 33 34 35
#include <class_track.h>
#include <class_module.h>
#include <class_pad.h>
#include <class_drawsegment.h>
#include <class_zone.h>
#include <class_pcb_text.h>
#include <class_colors_design_settings.h>
#include <class_marker_pcb.h>
#include <class_dimension.h>
36
#include <class_mire.h>
37
#include <class_netinfo.h>
38
#include <pcbstruct.h>
39 40 41 42 43

#include <view/view.h>
#include <pcb_painter.h>
#include <gal/graphics_abstraction_layer.h>

44
using namespace KIGFX;
45 46 47

PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS()
{
48 49 50 51 52 53
    // By default everything should be displayed as filled
    for( unsigned int i = 0; i < END_PCB_VISIBLE_LIST; ++i )
    {
        m_sketchModeSelect[i] = false;
    }

54
    update();
55 56 57 58 59
}


void PCB_RENDER_SETTINGS::ImportLegacyColors( COLORS_DESIGN_SETTINGS* aSettings )
{
Maciej Suminski's avatar
Maciej Suminski committed
60
    for( int i = 0; i < NB_LAYERS; i++ )
61 62 63 64 65 66
    {
        m_layerColors[i] = m_legacyColorMap[aSettings->GetLayerColor( i )];
    }

    for( int i = 0; i < END_PCB_VISIBLE_LIST; i++ )
    {
67
        m_layerColors[ITEM_GAL_LAYER( i )] = m_legacyColorMap[aSettings->GetItemColor( i )];
68 69
    }

70
    // Default colors for specific layers
71 72 73 74 75 76 77
    m_layerColors[ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE )]         = COLOR4D( 0.5, 0.4, 0.0, 1.0 );
    m_layerColors[ITEM_GAL_LAYER( PADS_HOLES_VISIBLE )]         = COLOR4D( 0.0, 0.5, 0.5, 1.0 );
    m_layerColors[ITEM_GAL_LAYER( VIAS_VISIBLE )]               = COLOR4D( 0.7, 0.7, 0.7, 1.0 );
    m_layerColors[ITEM_GAL_LAYER( PADS_VISIBLE )]               = COLOR4D( 0.7, 0.7, 0.7, 1.0 );
    m_layerColors[ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE )]      = COLOR4D( 0.8, 0.8, 0.8, 0.7 );
    m_layerColors[ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE )]    = COLOR4D( 0.8, 0.8, 0.8, 0.7 );
    m_layerColors[ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE )]    = COLOR4D( 0.8, 0.8, 0.8, 0.7 );
78
    m_layerColors[ITEM_GAL_LAYER( WORKSHEET )]                  = COLOR4D( 0.5, 0.0, 0.0, 1.0 );
79

80 81 82 83
    // Netnames for copper layers
    for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; ++layer )
    {
        // Quick, dirty hack, netnames layers should be stored in usual layers
84
        m_layerColors[GetNetnameLayer( layer )] = COLOR4D( 0.8, 0.8, 0.8, 0.7 );
85 86
    }

87
    update();
88 89 90
}


91 92 93
void PCB_RENDER_SETTINGS::LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions )
{
    m_hiContrastEnabled = aOptions.ContrastModeDisplay;
94
    m_padNumbers        = aOptions.DisplayPadNum;
95 96 97 98 99

    // Whether to draw tracks, vias & pads filled or as outlines
    m_sketchModeSelect[PADS_VISIBLE]   = !aOptions.DisplayPadFill;
    m_sketchModeSelect[VIAS_VISIBLE]   = !aOptions.DisplayViaFill;
    m_sketchModeSelect[TRACKS_VISIBLE] = !aOptions.DisplayPcbTrackFill;
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    switch( aOptions.DisplayNetNamesMode )
    {
    case 0:
        m_netNamesOnPads = false;
        m_netNamesOnTracks = false;
        break;

    case 1:
        m_netNamesOnPads = true;
        m_netNamesOnTracks = false;
        break;

    case 2:
        m_netNamesOnPads = false;
        m_netNamesOnTracks = true;
        break;

    case 3:
        m_netNamesOnPads = true;
        m_netNamesOnTracks = true;
        break;
    }

124 125 126 127 128 129 130 131 132 133 134 135 136 137
    switch( aOptions.DisplayZonesMode )
    {
    case 0:
        m_displayZoneMode = DZ_SHOW_FILLED;
        break;

    case 1:
        m_displayZoneMode = DZ_HIDE_FILLED;
        break;

    case 2:
        m_displayZoneMode = DZ_SHOW_OUTLINED;
        break;
    }
138 139 140
}


141
const COLOR4D& PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
142
{
143
    int netCode = -1;
144

145 146 147 148
    if( aItem )
    {
        if( static_cast<const EDA_ITEM*>( aItem )->IsSelected() )
        {
149
            return m_layerColorsSel[aLayer];
150
        }
151

152 153 154 155 156
        // Try to obtain the netcode for the item
        const BOARD_CONNECTED_ITEM* item = dynamic_cast<const BOARD_CONNECTED_ITEM*>( aItem );
        if( item )
            netCode = item->GetNet();
    }
157

158
    // Return grayish color for non-highlighted layers in the high contrast mode
159 160
    if( m_hiContrastEnabled && m_activeLayers.count( aLayer ) == 0 )
        return m_hiContrastColor;
161 162

    // Single net highlight mode
163
    if( m_highlightEnabled )
164
    {
165 166
        if( netCode == m_highlightNetcode )
            return m_layerColorsHi[aLayer];
167
        else
168
            return m_layerColorsDark[aLayer];
169
    }
170

171
    // No special modificators enabled
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
    return m_layerColors[aLayer];
}


void PCB_RENDER_SETTINGS::update()
{
    // Calculate darkened/highlighted variants of layer colors
    for( int i = 0; i < TOTAL_LAYER_COUNT; i++ )
    {
        m_layerColors[i].a   = m_layerOpacity;
        m_layerColorsHi[i]   = m_layerColors[i].Brightened( m_highlightFactor );
        m_layerColorsDark[i] = m_layerColors[i].Darkened( 1.0 - m_highlightFactor );
        m_layerColorsSel[i]  = m_layerColors[i].Brightened( m_selectFactor );
    }

    m_hiContrastColor = COLOR4D( m_hiContrastFactor, m_hiContrastFactor, m_hiContrastFactor,
                                 m_layerOpacity );
}


192 193 194 195
const COLOR4D& PCB_RENDER_SETTINGS::GetLayerColor( int aLayer ) const
{
    return m_layerColors[aLayer];
}
196

Maciej Suminski's avatar
Maciej Suminski committed
197

198 199 200
PCB_PAINTER::PCB_PAINTER( GAL* aGal ) :
    PAINTER( aGal )
{
201 202
    m_settings.reset( new PCB_RENDER_SETTINGS() );
    m_pcbSettings = (PCB_RENDER_SETTINGS*) m_settings.get();
203 204 205
}


206
bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
207 208
{
    // the "cast" applied in here clarifies which overloaded draw() is called
209
    switch( aItem->Type() )
210 211 212
    {
    case PCB_ZONE_T:
    case PCB_TRACE_T:
213
        draw( (TRACK*) aItem, aLayer );
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
        break;

    case PCB_VIA_T:
        draw( (SEGVIA*) aItem, aLayer );
        break;

    case PCB_PAD_T:
        draw( (D_PAD*) aItem, aLayer );
        break;

    case PCB_LINE_T:
    case PCB_MODULE_EDGE_T:
        draw( (DRAWSEGMENT*) aItem );
        break;

    case PCB_TEXT_T:
230
        draw( (TEXTE_PCB*) aItem, aLayer );
231 232 233 234 235 236 237 238 239 240
        break;

    case PCB_MODULE_TEXT_T:
        draw( (TEXTE_MODULE*) aItem, aLayer );
        break;

    case PCB_ZONE_AREA_T:
        draw( (ZONE_CONTAINER*) aItem );
        break;

241
    case PCB_DIMENSION_T:
242
        draw( (DIMENSION*) aItem, aLayer );
243 244 245 246 247 248
        break;

    case PCB_TARGET_T:
        draw( (PCB_TARGET*) aItem );
        break;

249
    default:
250
        // Painter does not know how to draw the object
251 252 253 254 255 256 257 258
        return false;
        break;
    }

    return true;
}


259
void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
260 261 262
{
    VECTOR2D start( aTrack->GetStart() );
    VECTOR2D end( aTrack->GetEnd() );
263
    int      width = aTrack->GetWidth();
264
    int      netNumber = aTrack->GetNet();
265
    COLOR4D  color;
266

267
    if( m_pcbSettings->m_netNamesOnTracks && IsNetnameLayer( aLayer ) )
268
    {
269
        // If there is a net name - display it on the track
270
        if( netNumber > 0 )
271 272 273 274 275 276 277 278 279
        {
            VECTOR2D line = ( end - start );
            double length = line.EuclideanNorm();

            // Check if the track is long enough to have a netname displayed
            if( length < 10 * width )
                return;

            NETINFO_ITEM* net = ( (BOARD*) aTrack->GetParent() )->FindNet( netNumber );
Maciej Suminski's avatar
Maciej Suminski committed
280
            if( !net )
281
                return;
282

283 284 285 286 287
            std::string netName = std::string( net->GetShortNetname().mb_str() );
            VECTOR2D textPosition = start + line / 2.0;     // center of the track
            double textOrientation = -atan( line.y / line.x );
            double textSize = std::min( static_cast<double>( width ), length / netName.length() );

288
            // Set a proper color for the label
289 290
            color = m_pcbSettings->GetColor( aTrack, aTrack->GetLayer() );
            COLOR4D labelColor = m_pcbSettings->GetColor( NULL, aLayer );
291

292
            if( color.GetBrightness() > 0.5 )
293
                m_gal->SetStrokeColor( labelColor.Inverted() );
294
            else
295
                m_gal->SetStrokeColor( labelColor );
296

297 298 299 300 301 302 303 304 305
            m_gal->SetLineWidth( width / 10.0 );
            m_gal->SetBold( false );
            m_gal->SetItalic( false );
            m_gal->SetMirrored( false );
            m_gal->SetGlyphSize( VECTOR2D( textSize * 0.7, textSize * 0.7 ) );
            m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER );
            m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );
            m_gal->StrokeText( netName, textPosition, textOrientation );
        }
306
    }
307
    else if( IsCopperLayer( aLayer ))
308
    {
309
        // Draw a regular track
310
        color = m_pcbSettings->GetColor( aTrack, aLayer );
311
        m_gal->SetStrokeColor( color );
312
        m_gal->SetIsStroke( true );
313

314 315 316 317 318 319 320 321 322 323 324 325 326 327
        if( m_pcbSettings->m_sketchModeSelect[TRACKS_VISIBLE] )
        {
            // Outline mode
            m_gal->SetLineWidth( m_pcbSettings->m_outlineWidth );
            m_gal->SetIsFill( false );
        }
        else
        {
            // Filled mode
            m_gal->SetFillColor( color );
            m_gal->SetIsFill( true );
        }
        m_gal->DrawSegment( start, end, width );
    }
328 329 330 331 332 333 334
}


void PCB_PAINTER::draw( const SEGVIA* aVia, int aLayer )
{
    VECTOR2D center( aVia->GetStart() );
    double   radius;
335
    COLOR4D  color;
336 337 338 339

    // Choose drawing settings depending on if we are drawing via's pad or hole
    if( aLayer == ITEM_GAL_LAYER( VIAS_VISIBLE ) )
    {
340
        radius = aVia->GetWidth() / 2.0;
341
    }
342
    else if( aLayer == ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ) )
343
    {
344
        radius = aVia->GetDrillValue() / 2.0;
345 346 347 348
    }
    else
        return;

349
    color = m_pcbSettings->GetColor( aVia, aLayer );
350

351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
    if( m_pcbSettings->m_sketchModeSelect[VIAS_VISIBLE] )
    {
        // Outline mode
        m_gal->SetIsFill( false );
        m_gal->SetIsStroke( true );
        m_gal->SetLineWidth( m_pcbSettings->m_outlineWidth );
        m_gal->SetStrokeColor( color );
        m_gal->DrawCircle( center, radius );
    }
    else
    {
        // Filled mode
        m_gal->SetIsFill( true );
        m_gal->SetIsStroke( false );
        m_gal->SetFillColor( color );
        m_gal->DrawCircle( center, radius );
    }
368 369 370 371 372
}


void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
{
373
    COLOR4D     color;
374
    VECTOR2D    size;
375
    VECTOR2D    position( aPad->GetPosition() );
376 377
    PAD_SHAPE_T shape;
    double      m, n;
378
    double      orientation = aPad->GetOrientation();
379
    wxString buffer;
380

381
    // Draw description layer
382
    if( IsNetnameLayer( aLayer ) )
383
    {
384 385
        // Is anything that we can display enabled?
        if( m_pcbSettings->m_netNamesOnPads || m_pcbSettings->m_padNumbers )
386
        {
387 388 389
            // Min char count to calculate string size
            #define MIN_CHAR_COUNT 3

390 391
            bool displayNetname = ( m_pcbSettings->m_netNamesOnPads &&
                                    !aPad->GetNetname().empty() );
392 393
            VECTOR2D padsize = VECTOR2D( aPad->GetSize() );
            double maxSize = PCB_RENDER_SETTINGS::MAX_FONT_SIZE;
394
            double size = padsize.y;
395 396

            // Keep the size ratio for the font, but make it smaller
397
            if( padsize.x < padsize.y )
398
            {
399 400 401
                orientation += 900.0;
                size = padsize.x;
                EXCHG( padsize.x, padsize.y );
402
            }
403
            else if( padsize.x == padsize.y )
404 405 406 407 408 409 410
            {
                // If the text is displayed on a symmetrical pad, do not rotate it
                orientation = 0.0;
            }
            else
            {
            }
411

412
            // Font size limits
413 414
            if( size > maxSize )
                size = maxSize;
415

416 417
            m_gal->Save();
            m_gal->Translate( position );
418 419 420 421

            // do not display descriptions upside down
            NORMALIZE_ANGLE_90( orientation );
            m_gal->Rotate( -orientation * M_PI / 1800.0 );
422

423 424 425 426 427 428
            // Default font settings
            m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER );
            m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );
            m_gal->SetBold( false );
            m_gal->SetItalic( false );
            m_gal->SetMirrored( false );
429

430
            // Set a proper color for the label
431 432
            color = m_pcbSettings->GetColor( aPad, aPad->GetLayer() );
            COLOR4D labelColor = m_pcbSettings->GetColor( NULL, aLayer );
433

434
            if( color.GetBrightness() > 0.5 )
435
                m_gal->SetStrokeColor( labelColor.Inverted() );
436
            else
437
                m_gal->SetStrokeColor( labelColor );
438

439
            VECTOR2D textpos( 0.0, 0.0);
440 441 442

            // Divide the space, to display both pad numbers and netnames
            // and set the Y text position to display 2 lines
443 444 445
            if( displayNetname && m_pcbSettings->m_padNumbers )
            {
                size = size / 2.0;
446 447
                textpos.y = size / 2.0;
            }
448

449 450 451 452 453 454 455 456
            if( displayNetname )
            {
                // calculate the size of net name text:
                double tsize = padsize.x / aPad->GetShortNetname().Length();
                tsize = std::min( tsize, size );
                // Use a smaller text size to handle interline, pen size..
                tsize *= 0.7;
                VECTOR2D namesize( tsize, tsize );
457
                m_gal->SetGlyphSize( namesize );
458
                m_gal->SetLineWidth( namesize.x / 12.0 );
459 460
                m_gal->StrokeText( std::string( aPad->GetShortNetname().mb_str() ),
                                   textpos, 0.0 );
461 462 463 464 465 466 467 468 469 470 471 472 473
            }

            if( m_pcbSettings->m_padNumbers )
            {
                textpos.y = -textpos.y;
                aPad->ReturnStringPadName( buffer );
                int len = buffer.Length();
                double tsize = padsize.x / std::max( len, MIN_CHAR_COUNT );
                tsize = std::min( tsize, size );
                // Use a smaller text size to handle interline, pen size..
                tsize *= 0.7;
                tsize = std::min( tsize, size );
                VECTOR2D numsize( tsize, tsize );
474 475

                m_gal->SetGlyphSize( numsize );
476
                m_gal->SetLineWidth( numsize.x / 12.0 );
477
                m_gal->StrokeText( std::string( aPad->GetPadName().mb_str() ),
478
                                   textpos, 0.0 );
479 480 481 482
            }

            m_gal->Restore();
        }
483 484 485
        return;
    }

486
    // Pad drawing
487
    color = m_pcbSettings->GetColor( aPad, aLayer );
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
    if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] )
    {
        // Outline mode
        m_gal->SetIsFill( false );
        m_gal->SetIsStroke( true );
        m_gal->SetLineWidth( m_pcbSettings->m_outlineWidth );
        m_gal->SetStrokeColor( color );
    }
    else
    {
        // Filled mode
        m_gal->SetIsFill( true );
        m_gal->SetIsStroke( false );
        m_gal->SetFillColor( color );
    }

504 505
    m_gal->Save();
    m_gal->Translate( VECTOR2D( aPad->GetPosition() ) );
506
    m_gal->Rotate( -aPad->GetOrientation() * M_PI / 1800.0 );
507

508
    // Choose drawing settings depending on if we are drawing a pad itself or a hole
509
    if( aLayer == ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ) )
510 511
    {
        // Drawing hole
512
        size  = VECTOR2D( aPad->GetDrillSize() ) / 2.0;
513 514
        shape = aPad->GetDrillShape();
    }
515 516 517
    else if( aLayer == SOLDERMASK_N_FRONT || aLayer == SOLDERMASK_N_BACK )
    {
        // Drawing soldermask
518 519 520 521 522 523 524 525 526 527 528 529
        int soldermaskMargin = aPad->GetSolderMaskMargin();

        m_gal->Translate( VECTOR2D( aPad->GetOffset() ) );
        size  = VECTOR2D( aPad->GetSize().x / 2.0 + soldermaskMargin,
                          aPad->GetSize().y / 2.0 + soldermaskMargin );
        shape = aPad->GetShape();
    }
    else if( aLayer == SOLDERPASTE_N_FRONT || aLayer == SOLDERPASTE_N_BACK )
    {
        // Drawing solderpaste
        int solderpasteMargin = aPad->GetLocalSolderPasteMargin();

530
        m_gal->Translate( VECTOR2D( aPad->GetOffset() ) );
531 532
        size  = VECTOR2D( aPad->GetSize().x / 2.0 + solderpasteMargin,
                          aPad->GetSize().y / 2.0 + solderpasteMargin );
533 534
        shape = aPad->GetShape();
    }
535 536 537 538
    else
    {
        // Drawing every kind of pad
        m_gal->Translate( VECTOR2D( aPad->GetOffset() ) );
539
        size  = VECTOR2D( aPad->GetSize() ) / 2.0;
540 541 542 543 544 545 546 547 548 549 550
        shape = aPad->GetShape();
    }

    switch( shape )
    {
    case PAD_OVAL:
        if( size.y >= size.x )
        {
            m = ( size.y - size.x );
            n = size.x;

551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
            if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] )
            {
                // Outline mode
                m_gal->DrawArc( VECTOR2D( 0, -m ), n, -M_PI, 0 );
                m_gal->DrawArc( VECTOR2D( 0, m ),  n, M_PI, 0 );
                m_gal->DrawLine( VECTOR2D( -n, -m ), VECTOR2D( -n, m ) );
                m_gal->DrawLine( VECTOR2D( n, -m ),  VECTOR2D( n, m ) );
            }
            else
            {
                // Filled mode
                m_gal->DrawCircle( VECTOR2D( 0, -m ), n );
                m_gal->DrawCircle( VECTOR2D( 0, m ),  n );
                m_gal->DrawRectangle( VECTOR2D( -n, -m ), VECTOR2D( n, m ) );
            }
566 567 568 569 570 571
        }
        else
        {
            m = ( size.x - size.y );
            n = size.y;

572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
            if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] )
            {
                // Outline mode
                m_gal->DrawArc( VECTOR2D( -m, 0 ), n, M_PI / 2, 3 * M_PI / 2 );
                m_gal->DrawArc( VECTOR2D( m, 0 ),  n, M_PI / 2, -M_PI / 2 );
                m_gal->DrawLine( VECTOR2D( -m, -n ), VECTOR2D( m, -n ) );
                m_gal->DrawLine( VECTOR2D( -m, n ),  VECTOR2D( m, n ) );
            }
            else
            {
                // Filled mode
                m_gal->DrawCircle( VECTOR2D( -m, 0 ), n );
                m_gal->DrawCircle( VECTOR2D( m, 0 ),  n );
                m_gal->DrawRectangle( VECTOR2D( -m, -n ), VECTOR2D( m, n ) );
            }
587 588 589 590 591 592 593
        }
        break;

    case PAD_RECT:
        m_gal->DrawRectangle( VECTOR2D( -size.x, -size.y ), VECTOR2D( size.x, size.y ) );
        break;

594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
    case PAD_TRAPEZOID:
    {
        std::deque<VECTOR2D> pointList;
        wxPoint corners[4];

        VECTOR2D padSize = VECTOR2D( aPad->GetSize().x, aPad->GetSize().y ) / 2;
        VECTOR2D deltaPadSize = size - padSize; // = solder[Paste/Mask]Margin or 0

        aPad->BuildPadPolygon( corners, wxSize( deltaPadSize.x, deltaPadSize.y ), 0.0 );
        pointList.push_back( VECTOR2D( corners[0] ) );
        pointList.push_back( VECTOR2D( corners[1] ) );
        pointList.push_back( VECTOR2D( corners[2] ) );
        pointList.push_back( VECTOR2D( corners[3] ) );

        if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] )
        {
            // Add the beginning point to close the outline
            pointList.push_back( pointList.front() );
            m_gal->DrawPolyline( pointList );
        }
        else
        {
            m_gal->DrawPolygon( pointList );
        }
    }
    break;

621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
    case PAD_CIRCLE:
        m_gal->DrawCircle( VECTOR2D( 0.0, 0.0 ), size.x );
        break;

    case PAD_OCTAGON:    // it is not used anywhere, neither you can set it using pcbnew..
    case PAD_NONE:
        break;
    }

    m_gal->Restore();
}


void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment )
{
636
    COLOR4D color = m_pcbSettings->GetColor( aSegment, aSegment->GetLayer() );
637 638 639

    m_gal->SetIsFill( false );
    m_gal->SetIsStroke( true );
640
    m_gal->SetStrokeColor( color );
641 642 643 644 645 646 647 648 649
    m_gal->SetLineWidth( aSegment->GetWidth() );

    switch( aSegment->GetShape() )
    {
    case S_SEGMENT:
        m_gal->DrawLine( VECTOR2D( aSegment->GetStart() ), VECTOR2D( aSegment->GetEnd() ) );
        break;

    case S_RECT:
650 651
        wxASSERT_MSG( false, wxT( "Not tested yet" ) );
        m_gal->DrawRectangle( VECTOR2D( aSegment->GetStart() ), VECTOR2D( aSegment->GetEnd() ) );
652 653 654 655 656 657 658 659 660 661 662 663 664
        break;

    case S_ARC:
        m_gal->DrawArc( VECTOR2D( aSegment->GetCenter() ), aSegment->GetRadius(),
                        aSegment->GetArcAngleStart() * M_PI / 1800.0,
                        ( aSegment->GetArcAngleStart() + aSegment->GetAngle() ) * M_PI / 1800.0 );
        break;

    case S_CIRCLE:
        m_gal->DrawCircle( VECTOR2D( aSegment->GetCenter() ), aSegment->GetRadius() );
        break;

    case S_POLYGON:
665 666 667 668 669 670 671 672 673 674 675 676
    {
        std::deque<VECTOR2D> pointsList;

        m_gal->SetIsFill( true );
        m_gal->SetIsStroke( false );
        m_gal->SetFillColor( color );

        m_gal->Save();

        MODULE* module = aSegment->GetParentModule();
        if( module )
        {
677
            m_gal->Translate( module->GetPosition() );
678 679
            m_gal->Rotate( -module->GetOrientation() * M_PI / 1800.0 );
        }
680 681 682 683 684 685
        else
        {
            // not tested
            m_gal->Translate( aSegment->GetPosition() );
            m_gal->Rotate( -aSegment->GetAngle() * M_PI / 1800.0 );
        }
686

687 688
        std::copy( aSegment->GetPolyPoints().begin(), aSegment->GetPolyPoints().end(),
                   std::back_inserter( pointsList ) );
689 690 691

        m_gal->SetLineWidth( aSegment->GetWidth() );
        m_gal->DrawPolyline( pointsList );
692
        m_gal->DrawPolygon( pointsList );
693 694

        m_gal->Restore();
695
        break;
696
    }
697 698 699 700 701 702 703 704 705 706 707 708 709 710

    case S_CURVE:
        m_gal->DrawCurve( VECTOR2D( aSegment->GetStart() ),
                          VECTOR2D( aSegment->GetBezControl1() ),
                          VECTOR2D( aSegment->GetBezControl2() ),
                          VECTOR2D( aSegment->GetEnd() ) );
        break;

    case S_LAST:
        break;
    }
}


711
void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer )
712
{
713 714
    if( aText->GetText().Length() == 0 )
        return;
715

716 717 718
    COLOR4D  strokeColor = m_pcbSettings->GetColor( aText, aText->GetLayer() );
    VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y );
    double   orientation = aText->GetOrientation() * M_PI / 1800.0;
719

720 721 722 723
    m_gal->SetStrokeColor( strokeColor );
    m_gal->SetLineWidth( aText->GetThickness() );
    m_gal->SetTextAttributes( aText );
    m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation );
724 725 726 727 728
}


void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
{
729 730
    if( aText->GetLength() == 0 )
        return;
731

732 733 734
    COLOR4D  strokeColor = m_pcbSettings->GetColor( aText, aLayer );
    VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y );
    double   orientation = aText->GetDrawRotation() * M_PI / 1800.0;
735

736 737 738 739
    m_gal->SetStrokeColor( strokeColor );
    m_gal->SetLineWidth( aText->GetThickness() );
    m_gal->SetTextAttributes( aText );
    m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation );
740 741 742
}


743
void PCB_PAINTER::draw( const ZONE_CONTAINER* aZone )
744
{
745
    COLOR4D color = m_pcbSettings->GetColor( aZone, aZone->GetLayer() );
746
    std::deque<VECTOR2D> corners;
747
    PCB_RENDER_SETTINGS::DisplayZonesMode displayMode = m_pcbSettings->m_displayZoneMode;
748

749 750 751
    // Draw the outline
    m_gal->SetStrokeColor( color );
    m_gal->SetIsFill( false );
752
    m_gal->SetIsStroke( true );
753
    m_gal->SetLineWidth( m_pcbSettings->m_outlineWidth );
754

755
    const CPolyLine* outline = aZone->Outline();
756 757 758 759 760 761 762 763 764 765 766
    for( int i = 0; i < outline->GetCornersCount(); ++i )
    {
        corners.push_back( VECTOR2D( outline->GetPos( i ) ) );
    }
    // The last point for closing the polyline
    corners.push_back( VECTOR2D( outline->GetPos( 0 ) ) );
    m_gal->DrawPolyline( corners );
    corners.clear();

    // Draw the filling
    if( displayMode != PCB_RENDER_SETTINGS::DZ_HIDE_FILLED )
767
    {
768
        const std::vector<CPolyPt> polyPoints = aZone->GetFilledPolysList().GetList();
769 770 771 772 773
        if( polyPoints.size() == 0 )  // Nothing to draw
            return;

        // Set up drawing options
        m_gal->SetFillColor( color );
774
        m_gal->SetLineWidth( aZone->GetThermalReliefCopperBridge() / 2.0 );
775 776 777 778 779 780 781 782 783 784 785 786 787

        if( displayMode == PCB_RENDER_SETTINGS::DZ_SHOW_FILLED )
        {
            m_gal->SetIsFill( true );
            m_gal->SetIsStroke( true );
        }
        else if( displayMode == PCB_RENDER_SETTINGS::DZ_SHOW_OUTLINED )
        {
            m_gal->SetIsFill( false );
            m_gal->SetIsStroke( true );
        }

        std::vector<CPolyPt>::const_iterator polyIterator;
788
        for( polyIterator = polyPoints.begin(); polyIterator != polyPoints.end(); polyIterator++ )
789
        {
790
            // Find out all of polygons and then draw them
791 792 793
            corners.push_back( VECTOR2D( *polyIterator ) );

            if( polyIterator->end_contour )
794
            {
795 796 797 798 799 800 801 802 803 804
                if( displayMode == PCB_RENDER_SETTINGS::DZ_SHOW_FILLED )
                {
                    m_gal->DrawPolygon( corners );
                    m_gal->DrawPolyline( corners );
                }
                else if( displayMode == PCB_RENDER_SETTINGS::DZ_SHOW_OUTLINED )
                {
                    m_gal->DrawPolyline( corners );
                }

805 806
                corners.clear();
            }
807 808 809
        }
    }
}
810 811


812
void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer )
813
{
814
    COLOR4D strokeColor = m_pcbSettings->GetColor( aDimension, aLayer );
815

816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
    m_gal->SetStrokeColor( strokeColor );
    m_gal->SetIsFill( false );
    m_gal->SetIsStroke( true );
    m_gal->SetLineWidth( aDimension->GetWidth() );

    // Draw an arrow
    m_gal->DrawLine( VECTOR2D( aDimension->m_crossBarO ), VECTOR2D( aDimension->m_crossBarF ) );
    m_gal->DrawLine( VECTOR2D( aDimension->m_featureLineGO ),
                     VECTOR2D( aDimension->m_featureLineGF ) );
    m_gal->DrawLine( VECTOR2D( aDimension->m_featureLineDO ),
                     VECTOR2D( aDimension->m_featureLineDF ) );
    m_gal->DrawLine( VECTOR2D( aDimension->m_arrowD1O ), VECTOR2D( aDimension->m_arrowD1F ) );
    m_gal->DrawLine( VECTOR2D( aDimension->m_arrowD2O ), VECTOR2D( aDimension->m_arrowD2F ) );
    m_gal->DrawLine( VECTOR2D( aDimension->m_arrowG1O ), VECTOR2D( aDimension->m_arrowG1F ) );
    m_gal->DrawLine( VECTOR2D( aDimension->m_arrowG2O ), VECTOR2D( aDimension->m_arrowG2F ) );

    // Draw text
    TEXTE_PCB& text = aDimension->Text();
    VECTOR2D position( text.GetTextPosition().x, text.GetTextPosition().y );
    double   orientation = text.GetOrientation() * M_PI / 1800.0;

    m_gal->SetLineWidth( text.GetThickness() );
    m_gal->SetTextAttributes( &text );
    m_gal->StrokeText( std::string( text.GetText().mb_str() ), position, orientation );
840 841 842 843 844
}


void PCB_PAINTER::draw( const PCB_TARGET* aTarget )
{
845
    COLOR4D  strokeColor = m_pcbSettings->GetColor( aTarget, aTarget->GetLayer() );
846 847
    VECTOR2D position( aTarget->GetPosition() );
    double   size, radius;
848

849 850 851 852 853 854 855 856 857
    m_gal->SetLineWidth( aTarget->GetWidth() );
    m_gal->SetStrokeColor( strokeColor );
    m_gal->SetIsFill( false );
    m_gal->SetIsStroke( true );

    m_gal->Save();
    m_gal->Translate( position );

    if( aTarget->GetShape() )
858
    {
859 860 861 862
        // shape x
        m_gal->Rotate( M_PI / 4.0 );
        size   = 2.0 * aTarget->GetSize() / 3.0;
        radius = aTarget->GetSize() / 2.0;
863 864 865
    }
    else
    {
866 867 868
        // shape +
        size   = aTarget->GetSize() / 2.0;
        radius = aTarget->GetSize() / 3.0;
869 870
    }

871 872
    m_gal->DrawLine( VECTOR2D( -size, 0.0 ), VECTOR2D( size, 0.0 ) );
    m_gal->DrawLine( VECTOR2D( 0.0, -size ), VECTOR2D( 0.0,  size ) );
873 874 875
    m_gal->DrawCircle( VECTOR2D( 0.0, 0.0 ), radius );

    m_gal->Restore();
876
}
877 878


879
const double PCB_RENDER_SETTINGS::MAX_FONT_SIZE = Millimeter2iu( 10.0 );