pcb_plot_params.cpp 14.8 KB
Newer Older
1 2

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

#include <wx/wx.h>
26 27 28 29 30
#include <pcb_plot_params.h>
#include <pcb_plot_params_lexer.h>
#include <layers_id_colors_and_visibility.h>
#include <plot_common.h>
#include <macros.h>
31

32

33
#define PLOT_LINEWIDTH_MIN        0
34 35 36 37 38 39 40 41 42 43
#define PLOT_LINEWIDTH_MAX        200
#define HPGL_PEN_DIAMETER_MIN     0
#define HPGL_PEN_DIAMETER_MAX     100
#define HPGL_PEN_SPEED_MIN        0
#define HPGL_PEN_SPEED_MAX        1000
#define HPGL_PEN_NUMBER_MIN       1
#define HPGL_PEN_NUMBER_MAX       16
#define HPGL_PEN_OVERLAY_MIN      0
#define HPGL_PEN_OVERLAY_MAX      0x100

44 45 46 47 48 49
extern int g_DrawDefaultLineThickness;

PCB_PLOT_PARAMS g_PcbPlotOptions;

using namespace PCBPLOTPARAMS_T;

50 51

static const char* getTokenName( T aTok )
52 53 54 55 56
{
    return PCB_PLOT_PARAMS_LEXER::TokenName( aTok );
}


57 58 59 60 61 62 63 64 65 66 67 68 69 70
static bool setInt( int* aInt, int aValue, int aMin, int aMax )
{
    int temp = aValue;

    if( aValue < aMin )
        temp = aMin;
    else if( aValue > aMax )
        temp = aMax;

    *aInt = temp;
    return (temp == aValue);
}


71 72 73 74 75 76 77
// PCB_PLOT_PARAMS

PCB_PLOT_PARAMS::PCB_PLOT_PARAMS()
{
    layerSelection         = LAYER_BACK | LAYER_FRONT
        | SILKSCREEN_LAYER_FRONT | SILKSCREEN_LAYER_BACK;
    useGerberExtensions    = true;
78
    m_SkipNPTH_Pads        = false;
79 80 81 82 83 84 85 86 87 88 89 90
    m_ExcludeEdgeLayer     = true;
    m_PlotLineWidth        = g_DrawDefaultLineThickness;
    m_PlotFrameRef         = false;
    m_PlotViaOnMaskLayer   = false;
    m_PlotMode             = FILLED;
    useAuxOrigin           = false;
    m_HPGLPenNum           = 1;
    m_HPGLPenSpeed         = 20;
    m_HPGLPenDiam          = 15;
    m_HPGLPenOvr           = 2;
    m_PlotPSColorOpt       = true;
    m_PlotPSNegative       = false;
91
    psA4Output             = false;
92 93 94 95 96 97 98 99 100 101 102 103 104 105
    m_PlotReference        = true;
    m_PlotValue            = true;
    m_PlotTextOther        = true;
    m_PlotInvisibleTexts   = false;
    m_PlotPadsOnSilkLayer  = false;
    subtractMaskFromSilk   = false;
    m_PlotFormat           = PLOT_FORMAT_GERBER;
    m_PlotMirror           = false;
    m_DrillShapeOpt        = SMALL_DRILL_SHAPE;
    m_AutoScale            = false;
    m_PlotScale            = 1.0;
    scaleSelection         = 1;
    m_FineScaleAdjustX     = 1.0;
    m_FineScaleAdjustY     = 1.0;
106
    m_FineWidthAdjust      = 0.;
107 108 109 110 111 112 113
    outputDirectory        = wxT( "" );
}


void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter,
                              int aNestLevel ) const throw( IO_ERROR )
{
114 115
    const char* falseStr = getTokenName( T_false );
    const char* trueStr = getTokenName( T_true );
116

117 118
    aFormatter->Print( aNestLevel, "(%s", getTokenName( T_pcbplotparams ) );
    aFormatter->Print( aNestLevel+1, "(%s %ld)\n", getTokenName( T_layerselection ),
119
                       layerSelection );
120
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_usegerberextensions ),
121
                       useGerberExtensions ? trueStr : falseStr );
122
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_excludeedgelayer ),
123
                       m_ExcludeEdgeLayer ? trueStr : falseStr );
124
    aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_linewidth ),
125
                       m_PlotLineWidth );
126
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_plotframeref ),
127
                       m_PlotFrameRef ? trueStr : falseStr );
128
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_viasonmask ),
129
                       m_PlotViaOnMaskLayer ? trueStr : falseStr );
130
    aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_mode ),
131
                       m_PlotMode );
132
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_useauxorigin ),
133
                       useAuxOrigin ? trueStr : falseStr );
134
    aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpennumber ),
135
                       m_HPGLPenNum );
136
    aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpenspeed ),
137
                       m_HPGLPenSpeed );
138
    aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpendiameter ),
139
                       m_HPGLPenDiam );
140
    aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpenoverlay ),
141
                       m_HPGLPenOvr );
142
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_pscolor ),
143
                       m_PlotPSColorOpt ? trueStr : falseStr );
144
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_psnegative ),
145
                       m_PlotPSNegative ? trueStr : falseStr );
146 147
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_psa4output ),
                       psA4Output ? trueStr : falseStr );
148
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_plotreference ),
149
                       m_PlotReference ? trueStr : falseStr );
150
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_plotvalue ),
151
                       m_PlotValue ? trueStr : falseStr );
152
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_plotothertext ),
153
                       m_PlotTextOther ? trueStr : falseStr );
154
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_plotinvisibletext ),
155
                       m_PlotInvisibleTexts ? trueStr : falseStr );
156
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_padsonsilk ),
157
                       m_PlotPadsOnSilkLayer ? trueStr : falseStr );
158
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_subtractmaskfromsilk ),
159
                       subtractMaskFromSilk ? trueStr : falseStr );
160
    aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_outputformat ),
161
                       m_PlotFormat );
162
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_mirror ),
163
                       m_PlotMirror ? trueStr : falseStr );
164
    aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_drillshape ),
165
                       m_DrillShapeOpt );
166
    aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_scaleselection ),
167
                       scaleSelection );
168
    aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_outputdirectory ),
169
                       aFormatter->Quotew( outputDirectory ).c_str() );
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
    aFormatter->Print( 0, ")\n" );
}


void PCB_PLOT_PARAMS::Parse( PCB_PLOT_PARAMS_PARSER* aParser ) throw( IO_ERROR, PARSE_ERROR )
{
    aParser->Parse( this );
}


bool PCB_PLOT_PARAMS::operator==( const PCB_PLOT_PARAMS &aPcbPlotParams ) const
{
    if( layerSelection != aPcbPlotParams.layerSelection )
        return false;
    if( useGerberExtensions != aPcbPlotParams.useGerberExtensions )
        return false;
    if( m_ExcludeEdgeLayer != aPcbPlotParams.m_ExcludeEdgeLayer )
        return false;
    if( m_PlotLineWidth != aPcbPlotParams.m_PlotLineWidth )
        return false;
    if( m_PlotFrameRef != aPcbPlotParams.m_PlotFrameRef )
        return false;
    if( m_PlotViaOnMaskLayer != aPcbPlotParams.m_PlotViaOnMaskLayer )
        return false;
    if( m_PlotMode != aPcbPlotParams.m_PlotMode )
        return false;
    if( useAuxOrigin != aPcbPlotParams.useAuxOrigin )
        return false;
    if( m_HPGLPenNum != aPcbPlotParams.m_HPGLPenNum )
        return false;
    if( m_HPGLPenSpeed != aPcbPlotParams.m_HPGLPenSpeed )
        return false;
    if( m_HPGLPenDiam != aPcbPlotParams.m_HPGLPenDiam )
        return false;
    if( m_HPGLPenOvr != aPcbPlotParams.m_HPGLPenOvr )
        return false;
    if( m_PlotPSColorOpt != aPcbPlotParams.m_PlotPSColorOpt )
        return false;
    if( m_PlotPSNegative != aPcbPlotParams.m_PlotPSNegative )
        return false;
210 211
    if( psA4Output != aPcbPlotParams.psA4Output )
        return false;
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
    if( m_PlotReference != aPcbPlotParams.m_PlotReference )
        return false;
    if( m_PlotValue != aPcbPlotParams.m_PlotValue )
        return false;
    if( m_PlotTextOther != aPcbPlotParams.m_PlotTextOther )
        return false;
    if( m_PlotInvisibleTexts != aPcbPlotParams.m_PlotInvisibleTexts )
        return false;
    if( m_PlotPadsOnSilkLayer != aPcbPlotParams.m_PlotPadsOnSilkLayer )
        return false;
    if( subtractMaskFromSilk != aPcbPlotParams.subtractMaskFromSilk )
        return false;
    if( m_PlotFormat != aPcbPlotParams.m_PlotFormat )
        return false;
    if( m_PlotMirror != aPcbPlotParams.m_PlotMirror )
        return false;
    if( m_DrillShapeOpt != aPcbPlotParams.m_DrillShapeOpt )
        return false;
    if( scaleSelection != aPcbPlotParams.scaleSelection )
        return false;
    if( !outputDirectory.IsSameAs( aPcbPlotParams.outputDirectory ) )
        return false;
    return true;
}


bool PCB_PLOT_PARAMS::operator!=( const PCB_PLOT_PARAMS &aPcbPlotParams ) const
{
    return !( *this == aPcbPlotParams );
}


244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
bool PCB_PLOT_PARAMS::SetHpglPenDiameter( int aValue )
{
    return setInt( &m_HPGLPenDiam, aValue, HPGL_PEN_DIAMETER_MIN, HPGL_PEN_DIAMETER_MAX );
}


bool PCB_PLOT_PARAMS::SetHpglPenSpeed( int aValue )
{
    return setInt( &m_HPGLPenSpeed, aValue, HPGL_PEN_SPEED_MIN, HPGL_PEN_SPEED_MAX );
}


bool PCB_PLOT_PARAMS::SetHpglPenOverlay( int aValue )
{
    return setInt( &m_HPGLPenOvr, aValue, HPGL_PEN_OVERLAY_MIN, HPGL_PEN_OVERLAY_MAX );
}


bool PCB_PLOT_PARAMS::SetPlotLineWidth( int aValue )
{
    return setInt( &m_PlotLineWidth, aValue, PLOT_LINEWIDTH_MIN, PLOT_LINEWIDTH_MAX );
}


268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
// PCB_PLOT_PARAMS_PARSER

PCB_PLOT_PARAMS_PARSER::PCB_PLOT_PARAMS_PARSER( LINE_READER* aReader ) :
    PCB_PLOT_PARAMS_LEXER( aReader )
{
}


PCB_PLOT_PARAMS_PARSER::PCB_PLOT_PARAMS_PARSER( char* aLine, wxString aSource ) :
    PCB_PLOT_PARAMS_LEXER( aLine, aSource )
{
}


void PCB_PLOT_PARAMS_PARSER::Parse( PCB_PLOT_PARAMS* aPcbPlotParams ) throw( IO_ERROR, PARSE_ERROR )
{
    T token;
    while( ( token = NextTok() ) != T_RIGHT )
    {
        if( token == T_EOF)
            Unexpected( T_EOF );

        if( token == T_LEFT )
            token = NextTok();

        if( token == T_pcbplotparams )
            continue;

        switch( token )
        {
        case T_layerselection:
            token = NextTok();
            if( token != T_NUMBER )
                Expecting( T_NUMBER );
            aPcbPlotParams->layerSelection = atol( CurText() );
            break;
        case T_usegerberextensions:
            aPcbPlotParams->useGerberExtensions = ParseBool();
            break;
307 308 309
        case T_psa4output:
            aPcbPlotParams->psA4Output = ParseBool();
            break;
310 311 312 313
        case T_excludeedgelayer:
            aPcbPlotParams->m_ExcludeEdgeLayer = ParseBool();
            break;
        case T_linewidth:
314 315
            aPcbPlotParams->m_PlotLineWidth = ParseInt( PLOT_LINEWIDTH_MIN,
                                                        PLOT_LINEWIDTH_MAX );
316 317 318 319 320 321 322 323
            break;
        case T_plotframeref:
            aPcbPlotParams->m_PlotFrameRef = ParseBool();
            break;
        case T_viasonmask:
            aPcbPlotParams->m_PlotViaOnMaskLayer = ParseBool();
            break;
        case T_mode:
324
            aPcbPlotParams->m_PlotMode = (EDA_DRAW_MODE_T)ParseInt( 0, 2 );
325 326 327 328 329
            break;
        case T_useauxorigin:
            aPcbPlotParams->useAuxOrigin = ParseBool();
            break;
        case T_hpglpennumber:
330 331
            aPcbPlotParams->m_HPGLPenNum = ParseInt( HPGL_PEN_NUMBER_MIN,
                                                     HPGL_PEN_NUMBER_MAX );
332 333
            break;
        case T_hpglpenspeed:
334 335
            aPcbPlotParams->m_HPGLPenSpeed = ParseInt( HPGL_PEN_SPEED_MIN,
                                                       HPGL_PEN_SPEED_MAX );
336 337
            break;
        case T_hpglpendiameter:
338 339
            aPcbPlotParams->m_HPGLPenDiam = ParseInt( HPGL_PEN_DIAMETER_MIN,
                                                      HPGL_PEN_DIAMETER_MAX );
340 341
            break;
        case T_hpglpenoverlay:
342 343
            aPcbPlotParams->m_HPGLPenOvr = ParseInt( HPGL_PEN_OVERLAY_MIN,
                                                     HPGL_PEN_OVERLAY_MIN );
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
            break;
        case T_pscolor:
            aPcbPlotParams->m_PlotPSColorOpt = ParseBool();
            break;
        case T_psnegative:
            aPcbPlotParams->m_PlotPSNegative = ParseBool();
            break;
        case T_plotreference:
            aPcbPlotParams->m_PlotReference = ParseBool();
            break;
        case T_plotvalue:
            aPcbPlotParams->m_PlotValue = ParseBool();
            break;
        case T_plotothertext:
            aPcbPlotParams->m_PlotTextOther = ParseBool();
            break;
        case T_plotinvisibletext:
            aPcbPlotParams->m_PlotInvisibleTexts = ParseBool();
            break;
        case T_padsonsilk:
            aPcbPlotParams->m_PlotPadsOnSilkLayer= ParseBool();
            break;
        case T_subtractmaskfromsilk:
            aPcbPlotParams->subtractMaskFromSilk = ParseBool();
            break;
        case T_outputformat:
370
            aPcbPlotParams->m_PlotFormat = ParseInt( 0, 3 );
371 372 373 374 375 376 377 378 379 380 381 382
            break;
        case T_mirror:
            aPcbPlotParams->m_PlotMirror = ParseBool();
            break;
        case T_drillshape:
            aPcbPlotParams->m_DrillShapeOpt = (PCB_PLOT_PARAMS::DrillShapeOptT) ParseInt( 0, 2 );
            break;
        case T_scaleselection:
            aPcbPlotParams->scaleSelection = ParseInt( 0, 4 );
            break;
        case T_outputdirectory:
            NeedSYMBOL();
383
            aPcbPlotParams->outputDirectory = FROM_UTF8( CurText() );
384 385 386 387 388 389 390 391 392 393 394 395
            break;
        default:
            Unexpected( CurText() );
            break;
        }
        NeedRIGHT();
    }
}


bool PCB_PLOT_PARAMS_PARSER::ParseBool() throw( IO_ERROR )
{
396 397
    T token = NeedSYMBOL();

398 399
    if( token != T_false && token != T_true )
        Expecting( "true|false" );
400 401

    return token == T_true;
402 403 404 405 406
}


int PCB_PLOT_PARAMS_PARSER::ParseInt( int aMin, int aMax ) throw( IO_ERROR )
{
407 408
    T token = NextTok();

409 410 411
    if( token != T_NUMBER )
        Expecting( T_NUMBER );

412 413 414 415 416 417
    int val = atoi( CurText() );

    if( val < aMin )
        val = aMin;
    else if( val > aMax )
        val = aMax;
418

419
    return val;
420
}