2011-10-31 20:49:48 +00:00
|
|
|
/*
|
|
|
|
* 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) 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
|
|
|
|
*/
|
2010-10-08 20:40:57 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxstruct.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
2010-10-08 20:40:57 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <protos.h>
|
|
|
|
#include <general.h>
|
|
|
|
#include <lib_draw_item.h>
|
2010-10-08 20:40:57 +00:00
|
|
|
|
|
|
|
const int fill_tab[3] = { 'N', 'F', 'f' };
|
|
|
|
|
|
|
|
//#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
|
|
|
|
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM::LIB_ITEM( KICAD_T aType,
|
|
|
|
LIB_COMPONENT* aComponent,
|
|
|
|
int aUnit,
|
|
|
|
int aConvert,
|
|
|
|
FILL_T aFillType ) :
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM( aType )
|
2010-10-08 20:40:57 +00:00
|
|
|
{
|
2010-10-20 20:24:26 +00:00
|
|
|
m_Unit = aUnit;
|
|
|
|
m_Convert = aConvert;
|
|
|
|
m_Fill = aFillType;
|
2010-12-08 20:12:46 +00:00
|
|
|
m_Parent = (EDA_ITEM*) aComponent;
|
2010-10-20 20:24:26 +00:00
|
|
|
m_typeName = _( "Undefined" );
|
|
|
|
m_isFillable = false;
|
|
|
|
m_eraseLastDrawItem = false;
|
2010-10-08 20:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
void LIB_ITEM::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList )
|
2010-10-08 20:40:57 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), m_typeName, CYAN ) );
|
2010-10-08 20:40:57 +00:00
|
|
|
|
|
|
|
if( m_Unit == 0 )
|
|
|
|
msg = _( "All" );
|
|
|
|
else
|
|
|
|
msg.Printf( wxT( "%d" ), m_Unit );
|
2012-01-09 20:26:55 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Unit" ), msg, BROWN ) );
|
2010-10-08 20:40:57 +00:00
|
|
|
|
|
|
|
if( m_Convert == 0 )
|
|
|
|
msg = _( "All" );
|
|
|
|
else if( m_Convert == 1 )
|
|
|
|
msg = _( "no" );
|
|
|
|
else if( m_Convert == 2 )
|
|
|
|
msg = _( "yes" );
|
|
|
|
else
|
|
|
|
msg = wxT( "?" );
|
2012-01-09 20:26:55 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Convert" ), msg, BROWN ) );
|
2010-10-08 20:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
|
2010-10-08 20:40:57 +00:00
|
|
|
{
|
|
|
|
return ( ( Type() == aOther.Type() )
|
|
|
|
&& ( m_Unit == aOther.m_Unit )
|
|
|
|
&& ( m_Convert == aOther.m_Convert )
|
2012-02-27 23:02:08 +00:00
|
|
|
&& compare( aOther ) == 0 );
|
2010-10-08 20:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
|
2010-10-08 20:40:57 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2012-02-27 23:02:08 +00:00
|
|
|
return ( compare( aOther ) < 0 );
|
2010-10-08 20:40:57 +00:00
|
|
|
}
|
2010-10-20 20:24:26 +00:00
|
|
|
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
void LIB_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, EDA_COLOR_T aColor,
|
2012-09-01 13:38:27 +00:00
|
|
|
GR_DRAWMODE aDrawMode, void* aData, const TRANSFORM& aTransform )
|
2010-10-20 20:24:26 +00:00
|
|
|
{
|
|
|
|
if( InEditMode() )
|
|
|
|
{
|
|
|
|
// Temporarily disable filling while the item is being edited.
|
|
|
|
FILL_T fillMode = m_Fill;
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T color = GetDefaultColor();
|
2010-10-20 20:24:26 +00:00
|
|
|
|
|
|
|
m_Fill = NO_FILL;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2012-01-24 17:46:32 +00:00
|
|
|
#ifndef USE_WX_OVERLAY
|
2010-10-20 20:24:26 +00:00
|
|
|
// Erase the old items using the previous attributes.
|
|
|
|
if( m_eraseLastDrawItem )
|
|
|
|
{
|
|
|
|
GRSetDrawMode( aDC, g_XorMode );
|
2011-12-29 20:11:42 +00:00
|
|
|
drawEditGraphics( aPanel->GetClipBox(), aDC, color );
|
2010-10-20 20:24:26 +00:00
|
|
|
drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData, aTransform );
|
|
|
|
}
|
2012-01-24 17:46:32 +00:00
|
|
|
#endif
|
2010-10-25 15:43:42 +00:00
|
|
|
// Calculate the new attributes at the current cursor position.
|
2010-10-20 20:24:26 +00:00
|
|
|
calcEdit( aOffset );
|
|
|
|
|
|
|
|
// Draw the items using the new attributes.
|
2011-12-29 20:11:42 +00:00
|
|
|
drawEditGraphics( aPanel->GetClipBox(), aDC, color );
|
2010-10-20 20:24:26 +00:00
|
|
|
drawGraphic( aPanel, aDC, wxPoint( 0, 0 ), color, g_XorMode, aData, aTransform );
|
|
|
|
|
|
|
|
m_Fill = fillMode;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drawGraphic( aPanel, aDC, aOffset, aColor, aDrawMode, aData, aTransform );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T LIB_ITEM::GetDefaultColor()
|
2010-10-20 20:24:26 +00:00
|
|
|
{
|
|
|
|
return ReturnLayerColor( LAYER_DEVICE );
|
|
|
|
}
|