lib_draw_item.cpp 4.39 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 26 27 28
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2004-2011 KiCad Developers, see change_log.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
 */

/**
 * @file lib_draw_item.cpp
 */
29

30 31 32 33
#include <fctsys.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <wxstruct.h>
34

35 36 37
#include <protos.h>
#include <general.h>
#include <lib_draw_item.h>
38 39 40 41 42 43

const int fill_tab[3] = { 'N', 'F', 'f' };

//#define DRAW_ARC_WITH_ANGLE       // Used to draw arcs


44 45 46 47 48
LIB_ITEM::LIB_ITEM( KICAD_T        aType,
                    LIB_COMPONENT* aComponent,
                    int            aUnit,
                    int            aConvert,
                    FILL_T         aFillType ) :
49
    EDA_ITEM( aType )
50
{
51 52 53
    m_Unit              = aUnit;
    m_Convert           = aConvert;
    m_Fill              = aFillType;
54
    m_Parent            = (EDA_ITEM*) aComponent;
55 56 57
    m_typeName          = _( "Undefined" );
    m_isFillable        = false;
    m_eraseLastDrawItem = false;
58 59 60
}


61
void LIB_ITEM::DisplayInfo( EDA_DRAW_FRAME* aFrame )
62 63 64 65 66 67 68 69 70 71
{
    wxString msg;

    aFrame->ClearMsgPanel();
    aFrame->AppendMsgPanel( _( "Type" ), m_typeName, CYAN );

    if( m_Unit == 0 )
        msg = _( "All" );
    else
        msg.Printf( wxT( "%d" ), m_Unit );
72

73 74 75 76 77 78 79 80 81 82
    aFrame->AppendMsgPanel( _( "Unit" ), msg, BROWN );

    if( m_Convert == 0 )
        msg = _( "All" );
    else if( m_Convert == 1 )
        msg = _( "no" );
    else if( m_Convert == 2 )
        msg = _( "yes" );
    else
        msg = wxT( "?" );
83

84 85 86 87
    aFrame->AppendMsgPanel( _( "Convert" ), msg, BROWN );
}


88
bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
89 90 91 92 93 94 95 96
{
    return ( ( Type() == aOther.Type() )
             && ( m_Unit == aOther.m_Unit )
             && ( m_Convert == aOther.m_Convert )
             && DoCompare( aOther ) == 0 );
}


97
bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
{
    int result = m_Convert - aOther.m_Convert;

    if( result != 0 )
        return result < 0;

    result = m_Unit - aOther.m_Unit;

    if( result != 0 )
        return result < 0;

    result = Type() - aOther.Type();

    if( result != 0 )
        return result < 0;

    return ( DoCompare( aOther ) < 0 );
}
116 117


118 119
void LIB_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor,
                     int aDrawMode, void* aData, const TRANSFORM& aTransform )
120 121 122 123 124 125 126 127
{
    if( InEditMode() )
    {
        // Temporarily disable filling while the item is being edited.
        FILL_T fillMode = m_Fill;
        int  color = GetDefaultColor();

        m_Fill = NO_FILL;
128
#ifndef USE_WX_OVERLAY
129 130 131 132
        // Erase the old items using the previous attributes.
        if( m_eraseLastDrawItem )
        {
            GRSetDrawMode( aDC, g_XorMode );
133
            drawEditGraphics( aPanel->GetClipBox(), aDC, color );
134 135
            drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData, aTransform );
        }
136
#endif
137
        // Calculate the new attributes at the current cursor position.
138 139 140
        calcEdit( aOffset );

        // Draw the items using the new attributes.
141
        drawEditGraphics( aPanel->GetClipBox(), aDC, color );
142 143 144 145 146 147 148 149 150 151 152
        drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData, aTransform );

        m_Fill = fillMode;
    }
    else
    {
        drawGraphic( aPanel, aDC, aOffset, aColor, aDrawMode, aData, aTransform );
    }
}


153
int LIB_ITEM::GetDefaultColor()
154 155 156
{
    return ReturnLayerColor( LAYER_DEVICE );
}