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) 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 class_libentry.cpp
|
|
|
|
*/
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <plot_common.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_sch_screen.h>
|
|
|
|
#include <richio.h>
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <template_fieldnames.h>
|
|
|
|
#include <transform.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <class_libentry.h>
|
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <lib_arc.h>
|
|
|
|
#include <lib_bezier.h>
|
|
|
|
#include <lib_circle.h>
|
|
|
|
#include <lib_polyline.h>
|
|
|
|
#include <lib_rectangle.h>
|
|
|
|
#include <lib_text.h>
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
#include <boost/foreach.hpp>
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
// Set this to 1 to print debugging output in alias and component destructors to verify
|
2010-10-04 18:54:14 +00:00
|
|
|
// objects get cleaned up properly.
|
|
|
|
#if defined( TRACE_DESTRUCTOR )
|
|
|
|
#undef TRACE_DESTRUCTOR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TRACE_DESTRUCTOR 0
|
|
|
|
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent ):
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM( LIB_ALIAS_T )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
root = aRootComponent;
|
2009-12-15 21:11:05 +00:00
|
|
|
name = aName;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS::LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_COMPONENT* aRootComponent ) :
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM( aAlias )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
name = aAlias.name;
|
|
|
|
root = aRootComponent;
|
|
|
|
description = aAlias.description;
|
|
|
|
keyWords = aAlias.keyWords;
|
|
|
|
docFileName = aAlias.docFileName;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS::~LIB_ALIAS()
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
#if TRACE_DESTRUCTOR
|
2011-10-31 20:49:48 +00:00
|
|
|
wxLogDebug( wxT( "Destroying alias \"%s\" of component \"%s\" with alias list count %d." ),
|
2010-10-25 15:43:42 +00:00
|
|
|
GetChars( name ), GetChars( root->GetName() ), root->m_aliases.size() );
|
|
|
|
#endif
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
wxString LIB_ALIAS::GetLibraryName()
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
if( GetComponent() )
|
|
|
|
return GetComponent()->GetLibraryName();
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
return wxString( _( "none" ) );
|
|
|
|
}
|
|
|
|
|
2010-10-12 10:28:30 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
bool LIB_ALIAS::IsRoot() const
|
2010-10-12 10:28:30 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
return name.CmpNoCase( root->GetName() ) == 0;
|
2010-10-12 10:28:30 +00:00
|
|
|
}
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2011-05-28 18:51:32 +00:00
|
|
|
CMP_LIBRARY* LIB_ALIAS::GetLibrary()
|
|
|
|
{
|
|
|
|
return root->GetLibrary();
|
|
|
|
}
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
|
2011-11-11 20:10:24 +00:00
|
|
|
bool LIB_ALIAS::SaveDoc( OUTPUTFORMATTER& aFormatter )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
|
2009-09-25 18:49:04 +00:00
|
|
|
return true;
|
|
|
|
|
2011-11-11 20:10:24 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
aFormatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( name ) );
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2011-11-11 20:10:24 +00:00
|
|
|
if( !description.IsEmpty() )
|
|
|
|
aFormatter.Print( 0, "D %s\n", TO_UTF8( description ) );
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2011-11-11 20:10:24 +00:00
|
|
|
if( !keyWords.IsEmpty() )
|
|
|
|
aFormatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2011-11-11 20:10:24 +00:00
|
|
|
if( !docFileName.IsEmpty() )
|
|
|
|
aFormatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2011-11-11 20:10:24 +00:00
|
|
|
aFormatter.Print( 0, "$ENDCMP\n" );
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
return false;
|
2011-11-11 20:10:24 +00:00
|
|
|
}
|
2009-09-25 18:49:04 +00:00
|
|
|
|
|
|
|
return true;
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
bool LIB_ALIAS::operator==( const wxChar* aName ) const
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
return name.CmpNoCase( aName ) == 0;
|
2009-08-27 11:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 )
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
return aItem1.GetName().CmpNoCase( aItem2.GetName() ) < 0;
|
2009-08-27 11:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 )
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
return aItem1->GetName().CmpNoCase( aItem2->GetName() );
|
2009-08-27 11:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_COMPONENT::LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary ) :
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM( LIB_COMPONENT_T )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
m_name = aName;
|
|
|
|
m_library = aLibrary;
|
2010-06-24 18:31:43 +00:00
|
|
|
m_dateModified = 0;
|
2010-10-25 15:43:42 +00:00
|
|
|
m_unitCount = 1;
|
2010-06-24 18:31:43 +00:00
|
|
|
m_pinNameOffset = 40;
|
2010-02-16 17:49:17 +00:00
|
|
|
m_options = ENTRY_NORMAL;
|
2012-01-22 17:20:22 +00:00
|
|
|
m_unitsLocked = false;
|
2010-06-24 18:31:43 +00:00
|
|
|
m_showPinNumbers = true;
|
|
|
|
m_showPinNames = true;
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
// Create the default alias if the name parameter is not empty.
|
2010-10-04 18:54:14 +00:00
|
|
|
if( !aName.IsEmpty() )
|
|
|
|
m_aliases.push_back( new LIB_ALIAS( aName, this ) );
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// Add the MANDATORY_FIELDS in RAM only. These are assumed to be present
|
|
|
|
// when the field editors are invoked.
|
2009-10-21 20:02:25 +00:00
|
|
|
LIB_FIELD* value = new LIB_FIELD( this, VALUE );
|
2009-12-15 21:11:05 +00:00
|
|
|
value->m_Text = aName;
|
|
|
|
drawings.push_back( value );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.push_back( new LIB_FIELD( this, REFERENCE ) );
|
2010-06-17 16:30:10 +00:00
|
|
|
drawings.push_back( new LIB_FIELD( this, FOOTPRINT ) );
|
|
|
|
drawings.push_back( new LIB_FIELD( this, DATASHEET ) );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary ) :
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM( aComponent )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM* newItem;
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
m_library = aLibrary;
|
|
|
|
m_name = aComponent.m_name;
|
2009-12-15 21:11:05 +00:00
|
|
|
m_FootprintList = aComponent.m_FootprintList;
|
2010-10-25 15:43:42 +00:00
|
|
|
m_unitCount = aComponent.m_unitCount;
|
2010-06-24 18:31:43 +00:00
|
|
|
m_unitsLocked = aComponent.m_unitsLocked;
|
|
|
|
m_pinNameOffset = aComponent.m_pinNameOffset;
|
|
|
|
m_showPinNumbers = aComponent.m_showPinNumbers;
|
|
|
|
m_showPinNames = aComponent.m_showPinNames;
|
|
|
|
m_dateModified = aComponent.m_dateModified;
|
2010-02-16 17:49:17 +00:00
|
|
|
m_options = aComponent.m_options;
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& oldItem, aComponent.GetDrawItemList() )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2011-02-21 13:54:29 +00:00
|
|
|
if( oldItem.IsNew() )
|
2009-09-25 18:49:04 +00:00
|
|
|
continue;
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
newItem = (LIB_ITEM*) oldItem.Clone();
|
2009-09-25 18:49:04 +00:00
|
|
|
newItem->SetParent( this );
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.push_back( newItem );
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
2010-10-04 18:54:14 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < aComponent.m_aliases.size(); i++ )
|
|
|
|
{
|
|
|
|
LIB_ALIAS* alias = new LIB_ALIAS( *aComponent.m_aliases[i], this );
|
|
|
|
m_aliases.push_back( alias );
|
|
|
|
}
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT::~LIB_COMPONENT()
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
#if TRACE_DESTRUCTOR
|
|
|
|
wxLogDebug( wxT( "Destroying component <%s> with alias list count of %d" ),
|
|
|
|
GetChars( GetName() ), m_aliases.size() );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// If the component is being delete directly rather than trough the library, free all
|
|
|
|
// of the memory allocated by the aliases.
|
|
|
|
if( !m_aliases.empty() )
|
|
|
|
{
|
|
|
|
LIB_ALIAS* alias;
|
|
|
|
|
|
|
|
while( !m_aliases.empty() )
|
|
|
|
{
|
|
|
|
alias = m_aliases.back();
|
|
|
|
m_aliases.pop_back();
|
|
|
|
delete alias;
|
|
|
|
}
|
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
wxString LIB_COMPONENT::GetLibraryName()
|
|
|
|
{
|
|
|
|
if( m_library != NULL )
|
|
|
|
return m_library->GetName();
|
|
|
|
|
|
|
|
return wxString( _( "none" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-24 11:27:38 +00:00
|
|
|
wxString LIB_COMPONENT::ReturnSubReference( int aUnit )
|
|
|
|
{
|
|
|
|
wxString subRef;
|
2011-04-15 16:41:31 +00:00
|
|
|
#if defined(KICAD_GOST)
|
2010-04-24 11:27:38 +00:00
|
|
|
subRef.Printf( wxT(".%d" ), aUnit);
|
|
|
|
#else
|
2010-04-28 18:32:13 +00:00
|
|
|
subRef.Append( wxChar(aUnit + 'A' - 1) );
|
2010-04-24 11:27:38 +00:00
|
|
|
#endif
|
|
|
|
return subRef;
|
|
|
|
}
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2010-10-22 12:11:52 +00:00
|
|
|
void LIB_COMPONENT::SetName( const wxString& aName )
|
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
m_name = aName;
|
2010-10-22 12:11:52 +00:00
|
|
|
GetValueField().m_Text = aName;
|
|
|
|
m_aliases[0]->SetName( aName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void LIB_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset, int aMulti,
|
2012-09-02 12:06:47 +00:00
|
|
|
int aConvert, GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor, const TRANSFORM& aTransform,
|
2010-10-20 20:24:26 +00:00
|
|
|
bool aShowPinText, bool aDrawFields, bool aOnlySelected )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
BASE_SCREEN* screen = aPanel->GetScreen();
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
GRSetDrawMode( aDc, aDrawMode );
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2010-03-28 14:46:49 +00:00
|
|
|
/* draw background for filled items using background option
|
|
|
|
* Solid lines will be drawn after the background
|
|
|
|
* Note also, background is not drawn when:
|
|
|
|
* printing in black and white
|
|
|
|
* If the color is not the default color (aColor != -1 )
|
|
|
|
*/
|
2012-09-02 12:06:47 +00:00
|
|
|
if( ! (screen->m_IsPrinting && GetGRForceBlackPenState())
|
|
|
|
&& (aColor == UNSPECIFIED_COLOR) )
|
2010-03-28 14:46:49 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& drawItem, drawings )
|
2010-03-28 14:46:49 +00:00
|
|
|
{
|
|
|
|
if( drawItem.m_Fill != FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
continue;
|
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( aOnlySelected && !drawItem.IsSelected() )
|
2010-03-28 14:46:49 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Do not draw an item while moving (the cursor handler does that)
|
|
|
|
if( drawItem.m_Flags & IS_MOVED )
|
|
|
|
continue;
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Do not draw items not attached to the current part
|
2010-03-28 14:46:49 +00:00
|
|
|
if( aMulti && drawItem.m_Unit && ( drawItem.m_Unit != aMulti ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aConvert && drawItem.m_Convert && ( drawItem.m_Convert != aConvert ) )
|
|
|
|
continue;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( drawItem.Type() == LIB_FIELD_T )
|
2010-03-28 14:46:49 +00:00
|
|
|
continue;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( drawItem.Type() == LIB_FIELD_T )
|
2010-03-28 14:46:49 +00:00
|
|
|
{
|
2010-11-20 19:53:00 +00:00
|
|
|
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode, (void*) NULL, aTransform );
|
2010-03-28 14:46:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now, draw only the background for items with
|
|
|
|
// m_Fill == FILLED_WITH_BG_BODYCOLOR:
|
2010-11-20 19:53:00 +00:00
|
|
|
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode, (void*) false, aTransform );
|
2010-03-28 14:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& drawItem, drawings )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
if( aOnlySelected && !drawItem.IsSelected() )
|
2009-09-04 18:57:37 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Do not draw an item while moving (the cursor handler does that)
|
2009-10-05 17:52:41 +00:00
|
|
|
if( drawItem.m_Flags & IS_MOVED )
|
2009-09-04 18:57:37 +00:00
|
|
|
continue;
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Do not draw items not attached to the current part
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aMulti && drawItem.m_Unit && ( drawItem.m_Unit != aMulti ) )
|
2009-09-04 18:57:37 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aConvert && drawItem.m_Convert && ( drawItem.m_Convert != aConvert ) )
|
2009-09-04 18:57:37 +00:00
|
|
|
continue;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( !aDrawFields && drawItem.Type() == LIB_FIELD_T )
|
2009-10-21 20:02:25 +00:00
|
|
|
continue;
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( drawItem.Type() == LIB_PIN_T )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2010-10-20 20:24:26 +00:00
|
|
|
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode, (void*) aShowPinText,
|
|
|
|
aTransform );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
else if( drawItem.Type() == LIB_FIELD_T )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2010-10-20 20:24:26 +00:00
|
|
|
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode, (void*) NULL, aTransform );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
2009-10-21 20:02:25 +00:00
|
|
|
else
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2010-03-28 14:46:49 +00:00
|
|
|
bool forceNoFill = drawItem.m_Fill == FILLED_WITH_BG_BODYCOLOR;
|
2010-10-20 20:24:26 +00:00
|
|
|
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode, (void*) forceNoFill,
|
|
|
|
aTransform );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Enable this to draw the anchor of the component.
|
2009-09-17 17:48:40 +00:00
|
|
|
#if 0
|
2010-02-08 18:15:42 +00:00
|
|
|
int len = aDc->DeviceToLogicalXRel( 3 );
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLine( aPanel->GetClipBox(), aDc, aOffset.x, aOffset.y - len, aOffset.x,
|
2009-12-15 21:11:05 +00:00
|
|
|
aOffset.y + len, 0, aColor );
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLine( aPanel->GetClipBox(), aDc, aOffset.x - len, aOffset.y, aOffset.x + len,
|
2009-12-15 21:11:05 +00:00
|
|
|
aOffset.y, 0, aColor );
|
2009-09-17 17:48:40 +00:00
|
|
|
#endif
|
2009-09-04 18:57:37 +00:00
|
|
|
|
|
|
|
/* Enable this to draw the bounding box around the component to validate
|
|
|
|
* the bounding box calculations. */
|
|
|
|
#if 0
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT bBox = GetBoundingBox( aMulti, aConvert );
|
2011-12-29 20:11:42 +00:00
|
|
|
GRRect( aPanel->GetClipBox(), aDc, bBox.GetOrigin().x, bBox.GetOrigin().y,
|
2009-09-04 18:57:37 +00:00
|
|
|
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::Plot( PLOTTER* aPlotter, int aUnit, int aConvert,
|
2010-10-20 20:24:26 +00:00
|
|
|
const wxPoint& aOffset, const TRANSFORM& aTransform )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aPlotter != NULL );
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
|
2009-10-05 17:52:41 +00:00
|
|
|
continue;
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
|
2009-10-05 17:52:41 +00:00
|
|
|
continue;
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->SetColor( ReturnLayerColor( LAYER_DEVICE ) );
|
|
|
|
bool fill = aPlotter->GetColorMode();
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
item.Plot( aPlotter, aOffset, fill, aTransform );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
void LIB_COMPONENT::RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel, wxDC* aDc )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aItem != NULL );
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// none of the MANDATOR_FIELDS may be removed in RAM, but they may be
|
|
|
|
// omitted when saving to disk.
|
2010-12-10 19:47:44 +00:00
|
|
|
if( aItem->Type() == LIB_FIELD_T )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
LIB_FIELD* field = (LIB_FIELD*) aItem;
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2010-12-07 16:10:42 +00:00
|
|
|
if( field->GetId() < MANDATORY_FIELDS )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2010-08-10 15:42:26 +00:00
|
|
|
wxLogWarning( _( "An attempt was made to remove the %s field \
|
|
|
|
from component %s in library %s." ),
|
2010-12-07 16:10:42 +00:00
|
|
|
GetChars( field->GetName() ), GetChars( GetName() ),
|
2009-10-21 20:02:25 +00:00
|
|
|
GetChars( GetLibraryName() ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEMS::iterator i;
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
for( i = drawings.begin(); i < drawings.end(); i++ )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( *i == aItem )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2011-02-24 22:29:43 +00:00
|
|
|
if( aDc != NULL )
|
2012-09-02 12:06:47 +00:00
|
|
|
aItem->Draw( aPanel, aDc, wxPoint( 0, 0 ), UNSPECIFIED_COLOR, g_XorMode, NULL, DefaultTransform );
|
2011-02-24 22:29:43 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.erase( i );
|
2011-02-24 22:29:43 +00:00
|
|
|
SetModified();
|
2009-10-21 20:02:25 +00:00
|
|
|
break;
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
void LIB_COMPONENT::AddDrawItem( LIB_ITEM* aItem )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aItem != NULL );
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.push_back( aItem );
|
|
|
|
drawings.sort();
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_ITEM* aItem, KICAD_T aType )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-10-08 16:45:59 +00:00
|
|
|
/* Return the next draw object pointer.
|
|
|
|
* If item is NULL return the first item of type in the list.
|
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
if( drawings.empty() )
|
2009-10-05 17:52:41 +00:00
|
|
|
return NULL;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aItem == NULL && aType == TYPE_NOT_INIT ) // type is unspecified
|
|
|
|
return &drawings[0];
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-10-08 16:45:59 +00:00
|
|
|
// Search for last item
|
|
|
|
size_t idx = 0;
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aItem )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
for( ; idx < drawings.size(); idx++ )
|
2009-10-08 16:45:59 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aItem == &drawings[idx] )
|
2009-10-08 16:45:59 +00:00
|
|
|
{
|
|
|
|
idx++; // Prepare the next item search
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-10-08 16:45:59 +00:00
|
|
|
// Search the next item
|
2009-12-15 21:11:05 +00:00
|
|
|
for( ; idx < drawings.size(); idx++ )
|
2009-10-08 16:45:59 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aType == TYPE_NOT_INIT || drawings[ idx ].Type() == aType )
|
|
|
|
return &drawings[ idx ];
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
return NULL;
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
void LIB_COMPONENT::GetPins( LIB_PINS& aList, int aUnit, int aConvert )
|
2009-10-14 19:43:31 +00:00
|
|
|
{
|
2009-10-26 12:01:46 +00:00
|
|
|
/* Notes:
|
2009-12-15 21:11:05 +00:00
|
|
|
* when aUnit == 0: no unit filtering
|
|
|
|
* when aConvert == 0: no convert (shape selection) filtering
|
2009-10-26 12:01:46 +00:00
|
|
|
* when .m_Unit == 0, the body item is common to units
|
2009-10-26 19:00:46 +00:00
|
|
|
* when .m_Convert == 0, the body item is common to shapes
|
2009-10-26 12:01:46 +00:00
|
|
|
*/
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2009-10-14 19:43:31 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item.Type() != LIB_PIN_T ) // we search pins only
|
2009-10-26 12:01:46 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Unit filtering:
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
|
2009-10-26 12:01:46 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Shape filtering:
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
|
2009-10-14 19:43:31 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aList.push_back( (LIB_PIN*) &item );
|
2009-10-14 19:43:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_PIN* LIB_COMPONENT::GetPin( const wxString& aNumber, int aUnit, int aConvert )
|
2009-10-30 19:26:25 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
wxString pNumber;
|
|
|
|
LIB_PINS pinList;
|
2009-10-30 19:26:25 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
GetPins( pinList, aUnit, aConvert );
|
2009-10-30 19:26:25 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < pinList.size(); i++ )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
wxASSERT( pinList[i]->Type() == LIB_PIN_T );
|
2009-10-30 19:26:25 +00:00
|
|
|
|
|
|
|
pinList[i]->ReturnPinStringNum( pNumber );
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aNumber == pNumber )
|
2009-10-30 19:26:25 +00:00
|
|
|
return pinList[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
size_t i;
|
|
|
|
LIB_FIELD& value = GetValueField();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// First line: it s a comment (component name for readers)
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, "#\n# %s\n#\n", TO_UTF8( value.m_Text ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Save data
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, "DEF" );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-12-30 18:06:12 +00:00
|
|
|
if( value.IsVisible() )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, " %s", TO_UTF8( value.m_Text ) );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, " ~%s", TO_UTF8( value.m_Text ) );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
LIB_FIELD& reference = GetReferenceField();
|
|
|
|
|
|
|
|
if( !reference.m_Text.IsEmpty() )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, " %s", TO_UTF8( reference.m_Text ) );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, " ~" );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, " %d %d %c %c %d %c %c\n",
|
|
|
|
0, m_pinNameOffset,
|
|
|
|
m_showPinNumbers ? 'Y' : 'N',
|
|
|
|
m_showPinNames ? 'Y' : 'N',
|
|
|
|
m_unitCount, m_unitsLocked ? 'L' : 'F',
|
|
|
|
m_options == ENTRY_POWER ? 'P' : 'N' );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
if( !SaveDateAndTime( aFormatter ) )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_FIELDS fields;
|
2009-10-21 20:02:25 +00:00
|
|
|
GetFields( fields );
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// Fixed fields:
|
|
|
|
// may have their own save policy so there is a separate loop for them.
|
|
|
|
for( i = 0; i < MANDATORY_FIELDS; ++i )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
if( !fields[i].m_Text.IsEmpty() )
|
|
|
|
{
|
2011-11-01 15:06:26 +00:00
|
|
|
if( !fields[i].Save( aFormatter ) )
|
2010-06-17 16:30:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// User defined fields:
|
|
|
|
// may have their own save policy so there is a separate loop for them.
|
|
|
|
|
|
|
|
int fieldId = MANDATORY_FIELDS; // really wish this would go away.
|
|
|
|
|
|
|
|
for( i = MANDATORY_FIELDS; i < fields.size(); ++i )
|
|
|
|
{
|
|
|
|
// There is no need to save empty fields, i.e. no reason to preserve field
|
|
|
|
// names now that fields names come in dynamically through the template
|
|
|
|
// fieldnames.
|
|
|
|
if( !fields[i].m_Text.IsEmpty() )
|
|
|
|
{
|
2010-12-07 16:10:42 +00:00
|
|
|
fields[i].SetId( fieldId++ );
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
if( !fields[i].Save( aFormatter ) )
|
2010-06-17 16:30:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
// Save the alias list: a line starting by "ALIAS". The first alias is the root
|
|
|
|
// and has the same name as the component. In the old library file format this
|
|
|
|
// alias does not get added to the alias list.
|
|
|
|
if( m_aliases.size() > 1 )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, "ALIAS" );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
for( i = 1; i < m_aliases.size(); i++ )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, " %s", TO_UTF8( m_aliases[i]->GetName() ) );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, "\n" );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Write the footprint filter list
|
2009-04-05 20:49:15 +00:00
|
|
|
if( m_FootprintList.GetCount() != 0 )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, "$FPLIST\n" );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
for( i = 0; i < m_FootprintList.GetCount(); i++ )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, " %s\n", TO_UTF8( m_FootprintList[i] ) );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, "$ENDFPLIST\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Save graphics items (including pins)
|
2009-12-15 21:11:05 +00:00
|
|
|
if( !drawings.empty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
/* we sort the draw items, in order to have an edition more easy,
|
|
|
|
* when a file editing "by hand" is made */
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.sort();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, "DRAW\n" );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item.Type() == LIB_FIELD_T )
|
2009-10-21 20:02:25 +00:00
|
|
|
continue;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
if( !item.Save( aFormatter ) )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, "ENDDRAW\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, "ENDDEF\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int unused;
|
|
|
|
char* p;
|
2009-12-15 21:11:05 +00:00
|
|
|
char* componentName;
|
2009-04-05 20:49:15 +00:00
|
|
|
char* prefix = NULL;
|
2011-10-31 20:49:48 +00:00
|
|
|
char* line;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
bool Res;
|
|
|
|
wxString Msg;
|
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
line = aLineReader.Line();
|
|
|
|
|
|
|
|
p = strtok( line, " \t\r\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( strcmp( p, "DEF" ) != 0 )
|
|
|
|
{
|
2011-10-31 20:49:48 +00:00
|
|
|
aErrorMsg.Printf( wxT( "DEF command expected in line %d, aborted." ),
|
|
|
|
aLineReader.LineNumber() );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Read DEF line:
|
2009-04-05 20:49:15 +00:00
|
|
|
char drawnum = 0;
|
|
|
|
char drawname = 0;
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
if( ( componentName = strtok( NULL, " \t\n" ) ) == NULL // Part name:
|
|
|
|
|| ( prefix = strtok( NULL, " \t\n" ) ) == NULL // Prefix name:
|
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL // NumOfPins:
|
2009-04-05 20:49:15 +00:00
|
|
|
|| sscanf( p, "%d", &unused ) != 1
|
2012-06-06 14:12:39 +00:00
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL // TextInside:
|
2010-06-24 18:31:43 +00:00
|
|
|
|| sscanf( p, "%d", &m_pinNameOffset ) != 1
|
2012-06-06 14:12:39 +00:00
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL // DrawNums:
|
2009-04-05 20:49:15 +00:00
|
|
|
|| sscanf( p, "%c", &drawnum ) != 1
|
2012-06-06 14:12:39 +00:00
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL // DrawNums:
|
2009-04-05 20:49:15 +00:00
|
|
|
|| sscanf( p, "%c", &drawname ) != 1
|
2012-06-06 14:12:39 +00:00
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL // m_unitCount:
|
2010-10-25 15:43:42 +00:00
|
|
|
|| sscanf( p, "%d", &m_unitCount ) != 1 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-10-31 20:49:48 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ),
|
|
|
|
aLineReader.LineNumber() );
|
|
|
|
|
|
|
|
while( aLineReader.ReadLine() )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2011-10-31 20:49:48 +00:00
|
|
|
line = aLineReader.Line();
|
|
|
|
|
|
|
|
p = strtok( line, " \t\n" );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( stricmp( p, "ENDDEF" ) == 0 )
|
|
|
|
break;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
// Ensure m_unitCount is >= 1 (could be read as 0 in old libraries)
|
|
|
|
if( m_unitCount < 1 )
|
|
|
|
m_unitCount = 1;
|
2009-12-17 11:03:26 +00:00
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
m_showPinNumbers = ( drawnum == 'N' ) ? false : true;
|
|
|
|
m_showPinNames = ( drawname == 'N' ) ? false : true;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Copy part name and prefix.
|
2009-10-21 20:02:25 +00:00
|
|
|
LIB_FIELD& value = GetValueField();
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( componentName[0] != '~' )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
m_name = value.m_Text = FROM_UTF8( componentName );
|
2011-11-08 16:37:25 +00:00
|
|
|
m_name = value.m_Text = m_name.MakeUpper();
|
2009-10-21 20:02:25 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
m_name = value.m_Text = FROM_UTF8( &componentName[1] );
|
2009-10-21 20:02:25 +00:00
|
|
|
value.m_Attributs |= TEXT_NO_VISIBLE;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
// Add the root alias to the alias list.
|
2010-10-25 15:43:42 +00:00
|
|
|
m_aliases.push_back( new LIB_ALIAS( m_name, this ) );
|
2010-10-04 18:54:14 +00:00
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
LIB_FIELD& reference = GetReferenceField();
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( strcmp( prefix, "~" ) == 0 )
|
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
reference.m_Text.Empty();
|
|
|
|
reference.m_Attributs |= TEXT_NO_VISIBLE;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
else
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
reference.m_Text = FROM_UTF8( prefix );
|
2009-10-21 20:02:25 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
// Copy optional infos
|
|
|
|
if( ( p = strtok( NULL, " \t\n" ) ) != NULL && *p == 'L' )
|
2010-06-24 18:31:43 +00:00
|
|
|
m_unitsLocked = true;
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( ( p = strtok( NULL, " \t\n" ) ) != NULL && *p == 'P' )
|
2010-02-16 17:49:17 +00:00
|
|
|
m_options = ENTRY_POWER;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-12-30 19:04:40 +00:00
|
|
|
// Read next lines, until "ENDDEF" is found
|
2011-10-31 20:49:48 +00:00
|
|
|
while( aLineReader.ReadLine() )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-10-31 20:49:48 +00:00
|
|
|
line = aLineReader.Line();
|
|
|
|
|
|
|
|
p = strtok( line, " \t\r\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// This is the error flag ( if an error occurs, Res = false)
|
2009-04-05 20:49:15 +00:00
|
|
|
Res = true;
|
|
|
|
|
2011-12-30 19:04:40 +00:00
|
|
|
if( *line == '#' ) // a comment
|
|
|
|
continue;
|
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
if( (*line == 'T') && (*(line + 1) == 'i') )
|
|
|
|
Res = LoadDateAndTime( aLineReader );
|
|
|
|
else if( *line == 'F' )
|
|
|
|
Res = LoadField( aLineReader, Msg );
|
2011-12-30 19:04:40 +00:00
|
|
|
else if( strcmp( p, "ENDDEF" ) == 0 ) // End of component description
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
else if( strcmp( p, "DRAW" ) == 0 )
|
2011-10-31 20:49:48 +00:00
|
|
|
Res = LoadDrawEntries( aLineReader, Msg );
|
2009-04-05 20:49:15 +00:00
|
|
|
else if( strncmp( p, "ALIAS", 5 ) == 0 )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
p = strtok( NULL, "\r\n" );
|
2009-12-15 21:11:05 +00:00
|
|
|
Res = LoadAliases( p, aErrorMsg );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else if( strncmp( p, "$FPLIST", 5 ) == 0 )
|
2011-10-31 20:49:48 +00:00
|
|
|
Res = LoadFootprints( aLineReader, Msg );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// End line or block analysis: test for an error
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !Res )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-08-19 19:34:03 +00:00
|
|
|
if( Msg.IsEmpty() )
|
2011-10-31 20:49:48 +00:00
|
|
|
aErrorMsg.Printf( wxT( "error occurred at line %d " ), aLineReader.LineNumber() );
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( wxT( "error <%s> occurred at line %d " ),
|
2011-10-31 20:49:48 +00:00
|
|
|
GetChars( Msg ), aLineReader.LineNumber() );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// If we are here, this part is O.k. - put it in:
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.sort();
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-10-31 20:49:48 +00:00
|
|
|
char* line;
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM* newEntry = NULL;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2011-10-31 20:49:48 +00:00
|
|
|
if( !aLineReader.ReadLine() )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg = wxT( "file ended prematurely loading component draw element" );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
line = aLineReader.Line();
|
|
|
|
|
|
|
|
if( strncmp( line, "ENDDRAW", 7 ) == 0 )
|
2008-12-31 09:27:19 +00:00
|
|
|
break;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
newEntry = NULL;
|
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
switch( line[0] )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2012-06-06 14:12:39 +00:00
|
|
|
case 'A': // Arc
|
2011-04-27 19:44:32 +00:00
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_ARC( this );
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
case 'C': // Circle
|
2011-04-27 19:44:32 +00:00
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_CIRCLE( this );
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
case 'T': // Text
|
2011-04-27 19:44:32 +00:00
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_TEXT( this );
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
case 'S': // Square
|
2011-04-27 19:44:32 +00:00
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_RECTANGLE( this );
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
case 'X': // Pin Description
|
2011-04-27 19:44:32 +00:00
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_PIN( this );
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
case 'P': // Polyline
|
2011-04-27 19:44:32 +00:00
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_POLYLINE( this );
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
case 'B': // Bezier Curves
|
2011-04-27 19:44:32 +00:00
|
|
|
newEntry = ( LIB_ITEM* ) new LIB_BEZIER( this );
|
2009-08-27 19:44:13 +00:00
|
|
|
break;
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
case '#': // Comment
|
|
|
|
continue;
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
default:
|
2011-10-31 20:49:48 +00:00
|
|
|
aErrorMsg.Printf( wxT( "undefined DRAW command %c" ), line[0] );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
if( !newEntry->Load( aLineReader, aErrorMsg ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( wxT( "error <%s> in DRAW command %c" ),
|
2011-10-31 20:49:48 +00:00
|
|
|
GetChars( aErrorMsg ), line[0] );
|
2009-04-05 20:49:15 +00:00
|
|
|
SAFE_DELETE( newEntry );
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Flush till end of draw section
|
2009-04-05 20:49:15 +00:00
|
|
|
do
|
|
|
|
{
|
2011-10-31 20:49:48 +00:00
|
|
|
if( !aLineReader.ReadLine() )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-08-10 15:42:26 +00:00
|
|
|
aErrorMsg = wxT( "file ended prematurely while attempting \
|
|
|
|
to flush to end of drawing section." );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-31 20:49:48 +00:00
|
|
|
} while( strncmp( line, "ENDDRAW", 7 ) != 0 );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.push_back( newEntry );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_COMPONENT::LoadAliases( char* aLine, wxString& aErrorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
char* text = strtok( aLine, " \t\r\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
while( text )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
m_aliases.push_back( new LIB_ALIAS( FROM_UTF8( text ), this ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
text = strtok( NULL, " \t\r\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
bool LIB_COMPONENT::LoadField( LINE_READER& aLineReader, wxString& aErrorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD* field = new LIB_FIELD( this );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
if( !field->Load( aLineReader, aErrorMsg ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
SAFE_DELETE( field );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-07 16:10:42 +00:00
|
|
|
if( field->GetId() < MANDATORY_FIELDS )
|
2009-08-19 19:34:03 +00:00
|
|
|
{
|
2010-12-07 16:10:42 +00:00
|
|
|
LIB_FIELD* fixedField = GetField( field->GetId() );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
// this will fire only if somebody broke a constructor or editor.
|
2010-09-09 17:37:25 +00:00
|
|
|
// MANDATORY_FIELDS are always present in ram resident components, no
|
2010-06-17 16:30:10 +00:00
|
|
|
// exceptions, and they always have their names set, even fixed fields.
|
|
|
|
wxASSERT( fixedField );
|
|
|
|
|
|
|
|
*fixedField = *field;
|
|
|
|
|
2010-12-07 16:10:42 +00:00
|
|
|
if( field->GetId() == VALUE )
|
2010-10-25 15:43:42 +00:00
|
|
|
m_name = field->m_Text;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2009-08-19 19:34:03 +00:00
|
|
|
SAFE_DELETE( field );
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2009-08-19 19:34:03 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.push_back( field );
|
2009-08-19 19:34:03 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
bool LIB_COMPONENT::LoadFootprints( LINE_READER& aLineReader, wxString& aErrorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-10-31 20:49:48 +00:00
|
|
|
char* line;
|
|
|
|
char* p;
|
|
|
|
|
2009-08-19 19:34:03 +00:00
|
|
|
while( true )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-10-31 20:49:48 +00:00
|
|
|
if( !aLineReader.ReadLine() )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg = wxT( "file ended prematurely while loading footprints" );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
line = aLineReader.Line();
|
|
|
|
p = strtok( line, " \t\r\n" );
|
|
|
|
|
|
|
|
if( stricmp( p, "$ENDFPLIST" ) == 0 )
|
2009-08-19 19:34:03 +00:00
|
|
|
break;
|
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
m_FootprintList.Add( FROM_UTF8( p ) );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT LIB_COMPONENT::GetBoundingBox( int aUnit, int aConvert ) const
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-05-16 16:59:47 +00:00
|
|
|
for( unsigned ii = 0; ii < drawings.size(); ii++ )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2012-05-16 16:59:47 +00:00
|
|
|
const LIB_ITEM& item = drawings[ii];
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
if( ( item.m_Unit > 0 ) && ( ( m_unitCount > 1 ) && ( aUnit > 0 )
|
2009-12-15 21:11:05 +00:00
|
|
|
&& ( aUnit != item.m_Unit ) ) )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2010-09-09 17:37:25 +00:00
|
|
|
if( item.m_Convert > 0 && ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if ( ( item.Type() == LIB_FIELD_T ) && !( ( LIB_FIELD& ) item ).IsVisible() )
|
2009-11-20 19:51:39 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bBox.Merge( item.GetBoundingBox() );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bBox;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
2008-12-31 15:01:29 +00:00
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT LIB_COMPONENT::GetBodyBoundingBox( int aUnit, int aConvert ) const
|
2011-02-27 19:54:01 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
|
2011-02-27 19:54:01 +00:00
|
|
|
|
2012-05-16 16:59:47 +00:00
|
|
|
for( unsigned ii = 0; ii < drawings.size(); ii++ )
|
2011-02-27 19:54:01 +00:00
|
|
|
{
|
2012-05-16 16:59:47 +00:00
|
|
|
const LIB_ITEM& item = drawings[ii];
|
|
|
|
|
2011-02-27 19:54:01 +00:00
|
|
|
if( ( item.m_Unit > 0 ) && ( ( m_unitCount > 1 ) && ( aUnit > 0 )
|
|
|
|
&& ( aUnit != item.m_Unit ) ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item.m_Convert > 0 && ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( item.Type() == LIB_FIELD_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bBox.Merge( item.GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return bBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
void LIB_COMPONENT::deleteAllFields()
|
2008-12-31 15:01:29 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEMS::iterator it;
|
2008-12-31 15:01:29 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
for( it = drawings.begin(); it!=drawings.end(); /* deleting */ )
|
2008-12-31 15:01:29 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( it->Type() != LIB_FIELD_T )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
++it;
|
2009-10-21 20:02:25 +00:00
|
|
|
continue;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// 'it' is not advanced, but should point to next in list after erase()
|
2011-03-09 14:30:39 +00:00
|
|
|
it = drawings.erase( it );
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_COMPONENT::SetFields( const std::vector <LIB_FIELD>& aFields )
|
|
|
|
{
|
|
|
|
deleteAllFields();
|
|
|
|
|
|
|
|
for( unsigned i=0; i<aFields.size(); ++i )
|
|
|
|
{
|
|
|
|
// drawings is a ptr_vector, new and copy an object on the heap.
|
|
|
|
LIB_FIELD* field = new LIB_FIELD( aFields[i] );
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.push_back( field );
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
|
|
|
|
2010-08-22 17:42:55 +00:00
|
|
|
// Reorder drawings: transparent polygons first, pins and text last.
|
2010-09-09 17:37:25 +00:00
|
|
|
// so texts have priority on screen.
|
2010-08-22 17:42:55 +00:00
|
|
|
drawings.sort();
|
2009-10-21 20:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
void LIB_COMPONENT::GetFields( LIB_FIELDS& aList )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
LIB_FIELD* field;
|
|
|
|
|
|
|
|
// The only caller of this function is the library field editor, so it
|
|
|
|
// establishes policy here.
|
|
|
|
|
|
|
|
// Grab the MANDATORY_FIELDS first, in expected order given by
|
|
|
|
// enum NumFieldType
|
|
|
|
for( int id=0; id<MANDATORY_FIELDS; ++id )
|
|
|
|
{
|
|
|
|
field = GetField( id );
|
|
|
|
|
|
|
|
// the MANDATORY_FIELDS are exactly that in RAM.
|
|
|
|
wxASSERT( field );
|
|
|
|
|
|
|
|
aList.push_back( *field );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now grab all the rest of fields.
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2008-12-31 15:01:29 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item.Type() != LIB_FIELD_T )
|
2009-10-21 20:02:25 +00:00
|
|
|
continue;
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
field = ( LIB_FIELD* ) &item;
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2010-12-07 16:10:42 +00:00
|
|
|
if( (unsigned) field->GetId() < MANDATORY_FIELDS )
|
2010-06-17 16:30:10 +00:00
|
|
|
continue; // was added above
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aList.push_back( *field );
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_FIELD* LIB_COMPONENT::GetField( int aId )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item.Type() != LIB_FIELD_T )
|
2009-10-21 20:02:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
LIB_FIELD* field = ( LIB_FIELD* ) &item;
|
|
|
|
|
2010-12-07 16:10:42 +00:00
|
|
|
if( field->GetId() == aId )
|
2009-10-21 20:02:25 +00:00
|
|
|
return field;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
LIB_FIELD* LIB_COMPONENT::FindField( const wxString& aFieldName )
|
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item.Type() != LIB_FIELD_T )
|
2010-06-17 16:30:10 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
LIB_FIELD* field = ( LIB_FIELD* ) &item;
|
|
|
|
|
2010-12-07 16:10:42 +00:00
|
|
|
if( field->GetName() == aFieldName )
|
2010-06-17 16:30:10 +00:00
|
|
|
return field;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_FIELD& LIB_COMPONENT::GetValueField()
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
|
|
|
LIB_FIELD* field = GetField( VALUE );
|
|
|
|
wxASSERT( field != NULL );
|
|
|
|
return *field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_FIELD& LIB_COMPONENT::GetReferenceField()
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
|
|
|
LIB_FIELD* field = GetField( REFERENCE );
|
|
|
|
wxASSERT( field != NULL );
|
|
|
|
return *field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
bool LIB_COMPONENT::SaveDateAndTime( OUTPUTFORMATTER& aFormatter )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int year, mon, day, hour, min, sec;
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
if( m_dateModified == 0 )
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
sec = m_dateModified & 63;
|
|
|
|
min = ( m_dateModified >> 6 ) & 63;
|
|
|
|
hour = ( m_dateModified >> 12 ) & 31;
|
|
|
|
day = ( m_dateModified >> 17 ) & 31;
|
|
|
|
mon = ( m_dateModified >> 22 ) & 15;
|
|
|
|
year = ( m_dateModified >> 26 ) + 1990;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-01 15:06:26 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_COMPONENT::LoadDateAndTime( char* aLine )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int year, mon, day, hour, min, sec;
|
|
|
|
|
|
|
|
year = mon = day = hour = min = sec = 0;
|
2011-05-13 13:15:28 +00:00
|
|
|
strtok( aLine, " \r\t\n" );
|
|
|
|
strtok( NULL, " \r\t\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
if( sscanf( aLine, "%d/%d/%d %d:%d:%d", &year, &mon, &day, &hour, &min, &sec ) != 6 )
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
m_dateModified = ( sec & 63 ) + ( ( min & 63 ) << 6 ) +
|
2011-10-31 20:49:48 +00:00
|
|
|
( ( hour & 31 ) << 12 ) + ( ( day & 31 ) << 17 ) +
|
|
|
|
( ( mon & 15 ) << 22 ) + ( ( year - 1990 ) << 26 );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::SetOffset( const wxPoint& aOffset )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
item.SetOffset( aOffset );
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
void LIB_COMPONENT::RemoveDuplicateDrawItems()
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.unique();
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
bool LIB_COMPONENT::HasConversion() const
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2012-05-16 16:59:47 +00:00
|
|
|
for( unsigned ii = 0; ii < drawings.size(); ii++ )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2012-05-16 16:59:47 +00:00
|
|
|
const LIB_ITEM& item = drawings[ii];
|
2009-10-05 17:52:41 +00:00
|
|
|
if( item.m_Convert > 1 )
|
2009-09-14 13:24:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::ClearStatus()
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2011-05-20 18:29:35 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
item.m_Flags = 0;
|
2011-05-20 18:29:35 +00:00
|
|
|
}
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
int LIB_COMPONENT::SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool aEditPinByPin )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
int itemCount = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
item.ClearFlags( SELECTED );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( ( item.m_Unit && item.m_Unit != aUnit )
|
|
|
|
|| ( item.m_Convert && item.m_Convert != aConvert ) )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item.Type() != LIB_PIN_T )
|
2009-09-25 18:49:04 +00:00
|
|
|
continue;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
// Specific rules for pins.
|
2010-06-24 18:31:43 +00:00
|
|
|
if( aEditPinByPin || m_unitsLocked
|
2009-12-15 21:11:05 +00:00
|
|
|
|| ( item.m_Convert && item.m_Convert != aConvert ) )
|
2009-09-25 18:49:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( item.Inside( aRect ) )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
item.SetFlags( SELECTED );
|
2009-12-15 21:11:05 +00:00
|
|
|
itemCount++;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
return itemCount;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::MoveSelectedItems( const wxPoint& aOffset )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
if( !item.IsSelected() )
|
2009-09-25 18:49:04 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
item.SetOffset( aOffset );
|
2011-12-21 13:42:02 +00:00
|
|
|
item.m_Flags = 0;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.sort();
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::ClearSelectedItems()
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2011-12-21 13:42:02 +00:00
|
|
|
{
|
|
|
|
item.m_Flags = 0;
|
|
|
|
}
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::DeleteSelectedItems()
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEMS::iterator item = drawings.begin();
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2010-03-08 19:21:44 +00:00
|
|
|
// We *do not* remove the 2 mandatory fields: reference and value
|
|
|
|
// so skip them (do not remove) if they are flagged selected.
|
2010-03-09 09:51:22 +00:00
|
|
|
// Skip also not visible items.
|
2010-09-09 17:37:25 +00:00
|
|
|
// But I think fields must not be deleted by a block delete command or other global command
|
2010-03-09 09:51:22 +00:00
|
|
|
// because they are not really graphic items
|
2010-03-08 19:21:44 +00:00
|
|
|
while( item != drawings.end() )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item->Type() == LIB_FIELD_T )
|
2010-03-08 19:21:44 +00:00
|
|
|
{
|
2010-03-09 09:51:22 +00:00
|
|
|
#if 0 // Set to 1 to allows fields deletion on block delete or other global command
|
2010-03-08 19:21:44 +00:00
|
|
|
LIB_FIELD& field = ( LIB_FIELD& ) *item;
|
2011-12-21 13:42:02 +00:00
|
|
|
|
2010-12-07 16:10:42 +00:00
|
|
|
if( (field.GetId() == REFERENCE) || (field.m_FieldId == VALUE) ||
|
2010-03-09 09:51:22 +00:00
|
|
|
(field.m_Attributs & TEXT_NO_VISIBLE) )
|
|
|
|
#endif
|
2011-12-21 13:42:02 +00:00
|
|
|
item->ClearFlags( SELECTED );
|
2010-03-08 19:21:44 +00:00
|
|
|
}
|
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( !item->IsSelected() )
|
2010-03-08 19:21:44 +00:00
|
|
|
item++;
|
2009-10-05 17:52:41 +00:00
|
|
|
else
|
2010-03-08 19:21:44 +00:00
|
|
|
item = drawings.erase( item );
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::CopySelectedItems( const wxPoint& aOffset )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2010-02-20 14:49:14 +00:00
|
|
|
/* *do not* use iterators here, because new items
|
|
|
|
* are added to drawings that is a boost::ptr_vector.
|
|
|
|
* When push_back elements in buffer,
|
|
|
|
* a memory reallocation can happen and will break pointers
|
|
|
|
*/
|
|
|
|
unsigned icnt = drawings.size();
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2010-02-20 14:49:14 +00:00
|
|
|
for( unsigned ii = 0; ii < icnt; ii++ )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM& item = drawings[ii];
|
2011-12-21 13:42:02 +00:00
|
|
|
|
2010-03-08 19:21:44 +00:00
|
|
|
// We *do not* copy fields because they are unique for the whole component
|
|
|
|
// so skip them (do not duplicate) if they are flagged selected.
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item.Type() == LIB_FIELD_T )
|
2011-12-21 13:42:02 +00:00
|
|
|
item.ClearFlags( SELECTED );
|
2010-03-08 19:21:44 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( !item.IsSelected() )
|
2009-09-25 18:49:04 +00:00
|
|
|
continue;
|
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
item.ClearFlags( SELECTED );
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
|
2011-12-21 13:42:02 +00:00
|
|
|
newItem->SetFlags( SELECTED );
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.push_back( newItem );
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
MoveSelectedItems( aOffset );
|
|
|
|
drawings.sort();
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2010-03-01 19:52:40 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& aCenter )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
if( !item.IsSelected() )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
|
|
|
|
2010-03-01 19:52:40 +00:00
|
|
|
item.MirrorHorizontal( aCenter );
|
2011-12-21 13:42:02 +00:00
|
|
|
item.m_Flags = 0;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.sort();
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
2011-05-20 18:29:35 +00:00
|
|
|
void LIB_COMPONENT::MirrorSelectedItemsV( const wxPoint& aCenter )
|
|
|
|
{
|
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
if( !item.IsSelected() )
|
2011-05-20 18:29:35 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
item.MirrorVertical( aCenter );
|
2011-12-21 13:42:02 +00:00
|
|
|
item.m_Flags = 0;
|
2011-05-20 18:29:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
drawings.sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LIB_COMPONENT::RotateSelectedItems( const wxPoint& aCenter )
|
|
|
|
{
|
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
if( !item.IsSelected() )
|
2011-05-20 18:29:35 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
item.Rotate( aCenter );
|
2011-12-21 13:42:02 +00:00
|
|
|
item.m_Flags = 0;
|
2011-05-20 18:29:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
drawings.sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert,
|
|
|
|
KICAD_T aType, const wxPoint& aPoint )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( ( aUnit && item.m_Unit && ( aUnit != item.m_Unit) )
|
|
|
|
|| ( aConvert && item.m_Convert && ( aConvert != item.m_Convert ) )
|
|
|
|
|| ( ( item.Type() != aType ) && ( aType != TYPE_NOT_INIT ) ) )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( item.HitTest( aPoint ) )
|
2009-10-05 17:52:41 +00:00
|
|
|
return &item;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
|
|
|
|
const wxPoint& aPoint, const TRANSFORM& aTransform )
|
2009-10-06 13:52:43 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
/* we use LocateDrawItem( int aUnit, int convert, KICAD_T type, const
|
2009-10-19 19:00:47 +00:00
|
|
|
* wxPoint& pt ) to search items.
|
2011-05-05 17:45:35 +00:00
|
|
|
* because this function uses DefaultTransform as orient/mirror matrix
|
|
|
|
* we temporary copy aTransform in DefaultTransform
|
2009-10-19 19:00:47 +00:00
|
|
|
*/
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM* item;
|
2010-12-23 10:00:55 +00:00
|
|
|
TRANSFORM transform = DefaultTransform;
|
2010-12-23 10:53:12 +00:00
|
|
|
DefaultTransform = aTransform;
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
item = LocateDrawItem( aUnit, aConvert, aType, aPoint );
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2009-10-06 13:52:43 +00:00
|
|
|
//Restore matrix
|
2010-12-23 10:00:55 +00:00
|
|
|
DefaultTransform = transform;
|
2009-10-08 16:45:59 +00:00
|
|
|
|
2009-10-06 13:52:43 +00:00
|
|
|
return item;
|
|
|
|
}
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-10-19 19:00:47 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::SetPartCount( int aCount )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
if( m_unitCount == aCount )
|
2009-10-05 17:52:41 +00:00
|
|
|
return;
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
if( aCount < m_unitCount )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEMS::iterator i;
|
2009-12-15 21:11:05 +00:00
|
|
|
i = drawings.begin();
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
while( i != drawings.end() )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( i->m_Unit > aCount )
|
|
|
|
i = drawings.erase( i );
|
2009-10-05 17:52:41 +00:00
|
|
|
else
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
int prevCount = m_unitCount;
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-12-17 11:03:26 +00:00
|
|
|
// We cannot use an iterator here, because when adding items in vector
|
|
|
|
// the buffer can be reallocated, that change the previous value of
|
|
|
|
// .begin() and .end() iterators and invalidate others iterators
|
|
|
|
unsigned imax = drawings.size();
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2009-12-17 11:03:26 +00:00
|
|
|
for( unsigned ii = 0; ii < imax; ii++ )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-17 11:03:26 +00:00
|
|
|
if( drawings[ii].m_Unit != 1 )
|
2009-10-05 17:52:41 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
for( int j = prevCount + 1; j <= aCount; j++ )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM* newItem = (LIB_ITEM*) drawings[ii].Clone();
|
2009-10-05 17:52:41 +00:00
|
|
|
newItem->m_Unit = j;
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.push_back( newItem );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.sort();
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
m_unitCount = aCount;
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::SetConversion( bool aSetConvert )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aSetConvert == HasConversion() )
|
2009-10-05 17:52:41 +00:00
|
|
|
return;
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
// Duplicate items to create the converted shape
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aSetConvert )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2012-06-06 14:12:39 +00:00
|
|
|
// Only pins are duplicated.
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item.Type() != LIB_PIN_T )
|
2009-10-05 17:52:41 +00:00
|
|
|
continue;
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( item.m_Convert == 1 )
|
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
|
2009-10-05 17:52:41 +00:00
|
|
|
newItem->m_Convert = 2;
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.push_back( newItem );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-17 11:03:26 +00:00
|
|
|
// Delete converted shape items because the converted shape does
|
2009-10-19 19:00:47 +00:00
|
|
|
// not exist
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEMS::iterator i = drawings.begin();
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
while( i != drawings.end() )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
|
|
|
if( i->m_Convert > 1 )
|
2009-12-15 21:11:05 +00:00
|
|
|
i = drawings.erase( i );
|
2009-10-05 17:52:41 +00:00
|
|
|
else
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-17 13:22:25 +00:00
|
|
|
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
wxArrayString LIB_COMPONENT::GetAliasNames( bool aIncludeRoot ) const
|
2010-02-17 13:22:25 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
wxArrayString names;
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ALIASES::const_iterator it;
|
2010-10-04 18:54:14 +00:00
|
|
|
|
|
|
|
for( it=m_aliases.begin(); it<m_aliases.end(); ++it )
|
2010-02-17 13:22:25 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
if( !aIncludeRoot && (*it)->IsRoot() )
|
2010-02-17 13:22:25 +00:00
|
|
|
continue;
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
names.Add( (*it)->GetName() );
|
2010-02-17 13:22:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
return names;
|
2010-02-17 13:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
bool LIB_COMPONENT::HasAlias( const wxString& aName ) const
|
2010-02-17 13:22:25 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
wxCHECK2_MSG( !aName.IsEmpty(), return false,
|
|
|
|
wxT( "Cannot get alias with an empty name, bad programmer." ) );
|
2010-02-17 13:22:25 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
for( size_t i = 0; i < m_aliases.size(); i++ )
|
|
|
|
{
|
|
|
|
if( aName.CmpNoCase( m_aliases[i]->GetName() ) == 0 )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-02-17 13:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
void LIB_COMPONENT::SetAliases( const wxArrayString& aAliasList )
|
2010-02-17 13:22:25 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
wxCHECK_RET( m_library == NULL,
|
2010-10-04 18:54:14 +00:00
|
|
|
wxT( "Component aliases cannot be changed when they are owned by a library." ) );
|
2010-02-17 13:22:25 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( aAliasList == GetAliasNames() )
|
|
|
|
return;
|
2010-02-17 13:22:25 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
// Add names not existing in the current component alias list.
|
|
|
|
for( size_t i = 0; i < aAliasList.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
if( HasAlias( aAliasList[ i ] ) )
|
|
|
|
continue;
|
2010-02-17 13:22:25 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
m_aliases.push_back( new LIB_ALIAS( aAliasList[ i ], this ) );
|
|
|
|
}
|
2010-02-17 13:22:25 +00:00
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Remove names in the current component that are not in the new alias list.
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ALIASES::iterator it;
|
2010-02-17 13:22:25 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
for( it = m_aliases.begin(); it < m_aliases.end(); it++ )
|
|
|
|
{
|
|
|
|
int index = aAliasList.Index( (*it)->GetName(), false );
|
2010-02-17 13:22:25 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( index != wxNOT_FOUND || (*it)->IsRoot() )
|
|
|
|
continue;
|
2010-02-17 13:22:25 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
it = m_aliases.erase( it );
|
|
|
|
}
|
2010-02-17 13:22:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
|
|
|
|
void LIB_COMPONENT::RemoveAlias( const wxString& aName )
|
2010-02-17 13:22:25 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
wxCHECK_RET( m_library == NULL,
|
2010-10-04 18:54:14 +00:00
|
|
|
wxT( "Component aliases cannot be changed when they are owned by a library." ) );
|
|
|
|
wxCHECK_RET( !aName.IsEmpty(), wxT( "Cannot get alias with an empty name." ) );
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ALIASES::iterator it;
|
2010-10-04 18:54:14 +00:00
|
|
|
|
|
|
|
for( it = m_aliases.begin(); it < m_aliases.end(); it++ )
|
|
|
|
{
|
|
|
|
if( aName.CmpNoCase( (*it)->GetName() ) == 0 )
|
|
|
|
{
|
|
|
|
m_aliases.erase( it );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-17 13:22:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
|
|
|
|
LIB_ALIAS* LIB_COMPONENT::RemoveAlias( LIB_ALIAS* aAlias )
|
2010-02-17 13:22:25 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
wxCHECK_MSG( aAlias != NULL, NULL, wxT( "Cannot remove alias by NULL pointer." ) );
|
|
|
|
|
|
|
|
LIB_ALIAS* nextAlias = NULL;
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ALIASES::iterator it = find( m_aliases.begin(), m_aliases.end(), aAlias );
|
2010-10-04 18:54:14 +00:00
|
|
|
|
|
|
|
if( it != m_aliases.end() )
|
|
|
|
{
|
|
|
|
bool rename = aAlias->IsRoot();
|
|
|
|
|
|
|
|
it = m_aliases.erase( it );
|
|
|
|
delete aAlias;
|
|
|
|
|
|
|
|
if( !m_aliases.empty() )
|
|
|
|
{
|
|
|
|
if( it == m_aliases.end() )
|
|
|
|
it = m_aliases.begin();
|
|
|
|
|
|
|
|
nextAlias = (*it);
|
|
|
|
|
|
|
|
if( rename )
|
|
|
|
SetName( nextAlias->GetName() );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextAlias;
|
2010-02-17 13:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-02 21:41:56 +00:00
|
|
|
void LIB_COMPONENT::RemoveAllAliases()
|
|
|
|
{
|
|
|
|
// Remove all of the aliases except the root alias.
|
|
|
|
while( m_aliases.size() > 1 )
|
|
|
|
m_aliases.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
LIB_ALIAS* LIB_COMPONENT::GetAlias( const wxString& aName )
|
2010-02-17 13:22:25 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
wxCHECK2_MSG( !aName.IsEmpty(), return NULL,
|
|
|
|
wxT( "Cannot get alias with an empty name. Bad programmer!" ) );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < m_aliases.size(); i++ )
|
|
|
|
{
|
|
|
|
if( aName.CmpNoCase( m_aliases[i]->GetName() ) == 0 )
|
|
|
|
return m_aliases[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2010-02-17 13:22:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
|
|
|
|
LIB_ALIAS* LIB_COMPONENT::GetAlias( size_t aIndex )
|
2010-02-17 13:22:25 +00:00
|
|
|
{
|
2010-10-04 18:54:14 +00:00
|
|
|
wxCHECK2_MSG( aIndex < m_aliases.size(), return NULL,
|
|
|
|
wxT( "Illegal alias list index, bad programmer." ) );
|
2010-09-09 17:37:25 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
return m_aliases[aIndex];
|
2010-02-17 13:22:25 +00:00
|
|
|
}
|
2010-12-02 21:41:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
void LIB_COMPONENT::AddAlias( const wxString& aName )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( !HasAlias( aName ),
|
|
|
|
wxT( "Component <" ) + GetName() + wxT( "> already has an alias <" ) +
|
|
|
|
aName + wxT( ">. Bad programmer." ) );
|
|
|
|
|
|
|
|
m_aliases.push_back( new LIB_ALIAS( aName, this ) );
|
|
|
|
}
|