2011-10-31 20:49:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-28 16:56:09 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
|
2019-07-30 01:57:41 +00:00
|
|
|
* Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors.
|
2011-10-31 20:49:48 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2020-10-25 04:49:02 +00:00
|
|
|
#include <widgets/msgpanel.h>
|
2010-10-08 20:40:57 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
2019-08-15 07:09:52 +00:00
|
|
|
#include <lib_item.h>
|
2010-10-08 20:40:57 +00:00
|
|
|
|
2020-10-15 08:48:02 +00:00
|
|
|
const int fill_tab[3] = { 'N', 'F', 'f' };
|
2010-10-08 20:40:57 +00:00
|
|
|
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM::LIB_ITEM( KICAD_T aType,
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_PART* aComponent,
|
2011-04-27 19:44:32 +00:00
|
|
|
int aUnit,
|
|
|
|
int aConvert,
|
2020-10-15 01:45:20 +00:00
|
|
|
FILL_TYPE 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;
|
2020-11-14 18:11:28 +00:00
|
|
|
m_parent = (EDA_ITEM*) aComponent;
|
2010-10-20 20:24:26 +00:00
|
|
|
m_isFillable = false;
|
2010-10-08 20:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
void LIB_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList )
|
2010-10-08 20:40:57 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2018-01-25 23:49:04 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), GetTypeName(), 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
|
|
|
|
2019-04-15 13:59:36 +00:00
|
|
|
if( m_Convert == LIB_ITEM::LIB_CONVERT::BASE )
|
2010-10-08 20:40:57 +00:00
|
|
|
msg = _( "no" );
|
2019-04-15 13:59:36 +00:00
|
|
|
else if( m_Convert == LIB_ITEM::LIB_CONVERT::DEMORGAN )
|
2010-10-08 20:40:57 +00:00
|
|
|
msg = _( "yes" );
|
|
|
|
else
|
|
|
|
msg = wxT( "?" );
|
2012-01-09 20:26:55 +00:00
|
|
|
|
2016-10-18 16:59:26 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Converted" ), msg, BROWN ) );
|
2010-10-08 20:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-13 13:39:52 +00:00
|
|
|
int LIB_ITEM::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
|
|
|
|
{
|
|
|
|
if( Type() != aOther.Type() )
|
|
|
|
return Type() - aOther.Type();
|
|
|
|
|
|
|
|
// When comparing unit LIB_ITEM objects, we ignore the unit number.
|
|
|
|
if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_Unit != aOther.m_Unit )
|
|
|
|
return m_Unit - aOther.m_Unit;
|
|
|
|
|
|
|
|
if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_Convert != aOther.m_Convert )
|
|
|
|
return m_Convert - m_Convert;
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
if( m_Fill != aOther.m_Fill )
|
2020-10-15 01:45:20 +00:00
|
|
|
return static_cast<int>( m_Fill ) - static_cast<int>( aOther.m_Fill );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2020-02-13 13:39:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2020-02-13 13:39:52 +00:00
|
|
|
return 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
|
|
|
|
|
|
|
|
2019-05-05 10:33:34 +00:00
|
|
|
bool LIB_ITEM::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
|
|
|
{
|
2020-11-14 18:11:28 +00:00
|
|
|
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
|
2019-05-05 10:33:34 +00:00
|
|
|
return false;
|
|
|
|
|
2019-05-10 22:24:27 +00:00
|
|
|
EDA_RECT sel = aRect;
|
2019-05-05 10:33:34 +00:00
|
|
|
|
|
|
|
if ( aAccuracy )
|
2019-05-10 22:24:27 +00:00
|
|
|
sel.Inflate( aAccuracy );
|
2019-05-05 10:33:34 +00:00
|
|
|
|
|
|
|
if( aContained )
|
2019-05-10 22:24:27 +00:00
|
|
|
return sel.Contains( GetBoundingBox() );
|
2019-05-05 10:33:34 +00:00
|
|
|
|
2019-05-10 22:24:27 +00:00
|
|
|
return sel.Intersects( GetBoundingBox() );
|
2019-05-05 10:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
void LIB_ITEM::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
|
|
|
|
const TRANSFORM& aTransform )
|
2010-10-20 20:24:26 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
print( aSettings, aOffset, aData, aTransform );
|
2010-10-20 20:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-21 12:50:31 +00:00
|
|
|
void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
// Basic fallback
|
2019-07-30 01:57:41 +00:00
|
|
|
aCount = 3;
|
2018-10-21 12:50:31 +00:00
|
|
|
aLayers[0] = LAYER_DEVICE;
|
|
|
|
aLayers[1] = LAYER_DEVICE_BACKGROUND;
|
2019-07-30 01:57:41 +00:00
|
|
|
aLayers[2] = LAYER_SELECTION_SHADOWS;
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|