2010-10-04 18:54:14 +00:00
|
|
|
/*************************/
|
|
|
|
/* class_libentry.cpp */
|
|
|
|
/*************************/
|
2008-12-31 09:27:19 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "macros.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "kicad_string.h"
|
2009-09-04 18:57:37 +00:00
|
|
|
#include "class_drawpanel.h"
|
2009-10-05 17:52:41 +00:00
|
|
|
#include "plot_common.h"
|
2009-09-04 18:57:37 +00:00
|
|
|
#include "gr_basic.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "template_fieldnames.h"
|
|
|
|
#include "transform.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
|
|
|
#include "class_libentry.h"
|
2010-10-22 12:11:52 +00:00
|
|
|
#include "lib_pin.h"
|
2010-10-08 20:40:57 +00:00
|
|
|
#include "lib_arc.h"
|
|
|
|
#include "lib_bezier.h"
|
|
|
|
#include "lib_circle.h"
|
|
|
|
#include "lib_polyline.h"
|
|
|
|
#include "lib_rectangle.h"
|
2010-10-22 12:11:52 +00:00
|
|
|
#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
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
// Set this to 1 to print debugging ouput in alias and component destructors to verify
|
|
|
|
// 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
|
|
|
/*******************************/
|
|
|
|
/* class LIB_ALIAS */
|
|
|
|
/*******************************/
|
|
|
|
|
|
|
|
/* Class to define an alias of a component
|
|
|
|
* An alias uses the component definition (graphic, pins...)
|
|
|
|
* but has its own name, keywords and documentation.
|
|
|
|
* Therefore, when the component is modified, alias of this component are
|
|
|
|
* modified.
|
|
|
|
* This is a simple method to create components with differs very few
|
|
|
|
* (like 74LS00, 74HC00 ... and many op amps )
|
2010-02-14 18:14:33 +00:00
|
|
|
*/
|
2008-12-31 09:27:19 +00:00
|
|
|
|
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
|
|
|
|
wxLogDebug( wxT( "Destroying alias \"%s\" of component \"%s\" with alais list count %d." ),
|
|
|
|
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
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
/**
|
|
|
|
* Function SaveDoc
|
|
|
|
* writes the doc info out to a FILE in "*.dcm" format.
|
|
|
|
* Only non empty fields are written.
|
|
|
|
* If all fields are empty, does not write anything
|
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
2010-10-25 15:43:42 +00:00
|
|
|
bool LIB_ALIAS::SaveDoc( FILE* aFile )
|
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-02-28 18:36:19 +00:00
|
|
|
if( fprintf( aFile, "#\n$CMP %s\n", TO_UTF8( name ) ) < 0 )
|
2009-09-25 18:49:04 +00:00
|
|
|
return false;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( ! description.IsEmpty()
|
2011-02-28 18:36:19 +00:00
|
|
|
&& fprintf( aFile, "D %s\n", TO_UTF8( description ) ) < 0 )
|
2009-09-25 18:49:04 +00:00
|
|
|
return false;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( ! keyWords.IsEmpty()
|
2011-02-28 18:36:19 +00:00
|
|
|
&& fprintf( aFile, "K %s\n", TO_UTF8( keyWords ) ) < 0 )
|
2009-09-25 18:49:04 +00:00
|
|
|
return false;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( ! docFileName.IsEmpty()
|
2011-02-28 18:36:19 +00:00
|
|
|
&& fprintf( aFile, "F %s\n", TO_UTF8( docFileName ) ) < 0 )
|
2009-09-25 18:49:04 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( fprintf( aFile, "$ENDCMP\n" ) < 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
/***********************/
|
2009-09-18 14:56:05 +00:00
|
|
|
/* class LIB_COMPONENT */
|
2010-10-04 18:54:14 +00:00
|
|
|
/***********************/
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2010-02-14 18:14:33 +00:00
|
|
|
/**
|
|
|
|
* Library component object definition.
|
|
|
|
*
|
|
|
|
* A library component object is typically saved and loaded
|
|
|
|
* in a component library file (.lib).
|
|
|
|
* Library components are different from schematic components.
|
2008-12-31 09:27:19 +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;
|
2010-06-24 18:31:43 +00:00
|
|
|
m_unitsLocked = FALSE;
|
|
|
|
m_showPinNumbers = true;
|
|
|
|
m_showPinNames = true;
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
// Create the default alias if the name paremeter is not empty.
|
|
|
|
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
|
|
|
{
|
|
|
|
LIB_DRAW_ITEM* newItem;
|
|
|
|
|
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
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_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;
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
newItem = oldItem.GenCopy();
|
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-11-12 16:36:43 +00:00
|
|
|
/**
|
2011-01-01 17:28:21 +00:00
|
|
|
* Function ReturnSubReference
|
2010-04-24 11:27:38 +00:00
|
|
|
* @return the sub reference for component having multiple parts per package.
|
|
|
|
* The sub reference identify the part (or unit)
|
|
|
|
* @param aUnit = the part identifier ( 1 to 26)
|
|
|
|
*/
|
|
|
|
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,
|
2010-10-20 20:24:26 +00:00
|
|
|
int aConvert, int aDrawMode, int aColor, const TRANSFORM& aTransform,
|
|
|
|
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 )
|
|
|
|
*/
|
|
|
|
if( ! (screen->m_IsPrinting && GetGRForceBlackPenState()) && (aColor == -1) )
|
|
|
|
{
|
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& drawItem, drawings )
|
|
|
|
{
|
|
|
|
if( drawItem.m_Fill != FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aOnlySelected && drawItem.m_Selected == 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Do not draw an item while moving (the cursor handler does that)
|
|
|
|
if( drawItem.m_Flags & IS_MOVED )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Do not draw items not attached to the current part */
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& drawItem, drawings )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aOnlySelected && drawItem.m_Selected == 0 )
|
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;
|
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2009-09-17 17:48:40 +00:00
|
|
|
/* Enable this to draw the anchor of the component. */
|
|
|
|
#if 0
|
2010-02-08 18:15:42 +00:00
|
|
|
int len = aDc->DeviceToLogicalXRel( 3 );
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
GRLine( &aPanel->m_ClipBox, aDc, aOffset.x, aOffset.y - len, aOffset.x,
|
|
|
|
aOffset.y + len, 0, aColor );
|
|
|
|
GRLine( &aPanel->m_ClipBox, aDc, aOffset.x - len, aOffset.y, aOffset.x + len,
|
|
|
|
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 );
|
2009-12-15 21:11:05 +00:00
|
|
|
GRRect( &aPanel->m_ClipBox, 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
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_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;
|
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;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
|
|
|
|
bool fill = aPlotter->get_color_mode();
|
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-01-21 19:30:59 +00:00
|
|
|
void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
LIB_DRAW_ITEM_LIST::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 )
|
|
|
|
aItem->Draw( aPanel, aDc, wxPoint( 0, 0 ), -1, g_XorMode, NULL, DefaultTransform );
|
|
|
|
|
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
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::AddDrawItem( LIB_DRAW_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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-09 17:37:25 +00:00
|
|
|
LIB_DRAW_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_DRAW_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;
|
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
|
|
|
|
|
|
|
void LIB_COMPONENT::GetPins( LIB_PIN_LIST& 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
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_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
|
|
|
{
|
|
|
|
wxString pNumber;
|
|
|
|
LIB_PIN_LIST pinList;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
bool LIB_COMPONENT::Save( FILE* aFile )
|
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
|
|
|
|
|
|
|
/* First line: it s a comment (component name for readers) */
|
2011-02-28 18:36:19 +00:00
|
|
|
if( fprintf( aFile, "#\n# %s\n#\n", TO_UTF8( value.m_Text ) ) < 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
/* Save data */
|
2009-09-14 13:24:17 +00:00
|
|
|
if( fprintf( aFile, "DEF" ) < 0 )
|
|
|
|
return false;
|
|
|
|
|
2009-12-30 18:06:12 +00:00
|
|
|
if( value.IsVisible() )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
if( fprintf( aFile, " %s", TO_UTF8( value.m_Text ) ) < 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
if( fprintf( aFile, " ~%s", TO_UTF8( value.m_Text ) ) < 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
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-02-28 18:36:19 +00:00
|
|
|
if( fprintf( aFile, " %s", TO_UTF8( reference.m_Text ) ) < 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
if( fprintf( aFile, " ~" ) < 0 )
|
|
|
|
return false;
|
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
if( fprintf( aFile, " %d %d %c %c %d %c %c\n",
|
2010-06-24 18:31:43 +00:00
|
|
|
0, m_pinNameOffset,
|
|
|
|
m_showPinNumbers ? 'Y' : 'N',
|
|
|
|
m_showPinNames ? 'Y' : 'N',
|
2010-10-25 15:43:42 +00:00
|
|
|
m_unitCount, m_unitsLocked ? 'L' : 'F',
|
2010-02-16 17:49:17 +00:00
|
|
|
m_options == ENTRY_POWER ? 'P' : 'N' ) < 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
if( !SaveDateAndTime( aFile ) )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
LIB_FIELD_LIST fields;
|
|
|
|
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() )
|
|
|
|
{
|
|
|
|
if( !fields[i].Save( aFile ) )
|
|
|
|
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++ );
|
2010-06-17 16:30:10 +00:00
|
|
|
if( !fields[i].Save( aFile ) )
|
|
|
|
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
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
if( fprintf( aFile, "ALIAS" ) < 0 )
|
|
|
|
return false;
|
|
|
|
|
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-02-28 18:36:19 +00:00
|
|
|
if( fprintf( aFile, " %s", TO_UTF8( m_aliases[i]->GetName() ) ) < 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
if( fprintf( aFile, "\n" ) < 0 )
|
|
|
|
return false;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* Write the footprint filter list */
|
|
|
|
if( m_FootprintList.GetCount() != 0 )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
if( fprintf( aFile, "$FPLIST\n" ) < 0 )
|
|
|
|
return false;
|
|
|
|
|
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-02-28 18:36:19 +00:00
|
|
|
if( fprintf( aFile, " %s\n", TO_UTF8( m_FootprintList[i] ) ) < 0 )
|
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
|
|
|
if( fprintf( aFile, "$ENDFPLIST\n" ) < 0 )
|
|
|
|
return false;
|
2009-04-05 20:49:15 +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
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
if( fprintf( aFile, "DRAW\n" ) < 0 )
|
|
|
|
return false;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_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
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( !item.Save( aFile ) )
|
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
|
|
|
|
|
|
|
if( fprintf( aFile, "ENDDRAW\n" ) < 0 )
|
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
if( fprintf( aFile, "ENDDEF\n" ) < 0 )
|
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum, 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;
|
|
|
|
|
|
|
|
bool Res;
|
|
|
|
wxString Msg;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
p = strtok( aLine, " \t\r\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( strcmp( p, "DEF" ) != 0 )
|
|
|
|
{
|
2010-09-09 17:37:25 +00:00
|
|
|
aErrorMsg.Printf( wxT( "DEF command expected in line %d, aborted." ), *aLineNum );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read DEF line: */
|
|
|
|
char drawnum = 0;
|
|
|
|
char drawname = 0;
|
|
|
|
|
2009-12-15 21:11:05 +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
|
2009-12-15 21:11:05 +00:00
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* TextInside: */
|
2010-06-24 18:31:43 +00:00
|
|
|
|| sscanf( p, "%d", &m_pinNameOffset ) != 1
|
2009-12-15 21:11:05 +00:00
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* DrawNums: */
|
2009-04-05 20:49:15 +00:00
|
|
|
|| sscanf( p, "%c", &drawnum ) != 1
|
2009-12-15 21:11:05 +00:00
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* DrawNums: */
|
2009-04-05 20:49:15 +00:00
|
|
|
|| sscanf( p, "%c", &drawname ) != 1
|
2010-10-25 15:43:42 +00:00
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* m_unitCount: */
|
|
|
|
|| sscanf( p, "%d", &m_unitCount ) != 1 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-09-09 17:37:25 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ), *aLineNum );
|
2010-06-10 18:43:12 +00:00
|
|
|
while( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
p = strtok( aLine, " \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
|
|
|
|
|
|
|
/* 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
|
|
|
strupper( componentName );
|
|
|
|
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 );
|
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;
|
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
|
|
|
|
|
|
|
/* Read next lines */
|
2010-06-10 18:43:12 +00:00
|
|
|
while( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
p = strtok( aLine, " \t\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
/* This is the error flag ( if an error occurs, Res = FALSE) */
|
|
|
|
Res = true;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( (aLine[0] == 'T') && (aLine[1] == 'i') )
|
|
|
|
Res = LoadDateAndTime( aLine );
|
|
|
|
else if( aLine[0] == 'F' )
|
|
|
|
Res = LoadField( aLine, Msg );
|
2009-04-05 20:49:15 +00:00
|
|
|
else if( strcmp( p, "ENDDEF" ) == 0 )
|
|
|
|
break;
|
|
|
|
else if( strcmp( p, "DRAW" ) == 0 )
|
2009-12-15 21:11:05 +00:00
|
|
|
Res = LoadDrawEntries( aFile, aLine, aLineNum, 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 )
|
2009-12-15 21:11:05 +00:00
|
|
|
Res = LoadFootprints( aFile, aLine, aLineNum, Msg );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* End line or block analysis: test for an error */
|
|
|
|
if( !Res )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-08-19 19:34:03 +00:00
|
|
|
if( Msg.IsEmpty() )
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( wxT( "error occurred at line %d " ), *aLineNum );
|
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 " ),
|
|
|
|
GetChars( Msg ), *aLineNum );
|
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
|
|
|
/* 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
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_COMPONENT::LoadDrawEntries( FILE* aFile, char* aLine,
|
|
|
|
int* aLineNum, wxString& aErrorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM* newEntry = NULL;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2010-06-10 18:43:12 +00:00
|
|
|
if( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) == NULL )
|
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
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( strncmp( aLine, "ENDDRAW", 7 ) == 0 )
|
2008-12-31 09:27:19 +00:00
|
|
|
break;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
newEntry = NULL;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
switch( aLine[0] )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
case 'A': /* Arc */
|
2009-10-08 13:19:28 +00:00
|
|
|
newEntry = ( LIB_DRAW_ITEM* ) new LIB_ARC(this);
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C': /* Circle */
|
2009-10-08 13:19:28 +00:00
|
|
|
newEntry = ( LIB_DRAW_ITEM* ) new LIB_CIRCLE(this);
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'T': /* Text */
|
2009-10-08 13:19:28 +00:00
|
|
|
newEntry = ( LIB_DRAW_ITEM* ) new LIB_TEXT(this);
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S': /* Square */
|
2009-10-08 13:19:28 +00:00
|
|
|
newEntry = ( LIB_DRAW_ITEM* ) new LIB_RECTANGLE(this);
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X': /* Pin Description */
|
2009-10-08 13:19:28 +00:00
|
|
|
newEntry = ( LIB_DRAW_ITEM* ) new LIB_PIN(this);
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P': /* Polyline */
|
2009-10-08 13:19:28 +00:00
|
|
|
newEntry = ( LIB_DRAW_ITEM* ) new LIB_POLYLINE(this);
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-08-27 19:44:13 +00:00
|
|
|
case 'B': /* Bezier Curves */
|
2009-10-08 13:19:28 +00:00
|
|
|
newEntry = ( LIB_DRAW_ITEM* ) new LIB_BEZIER(this);
|
2009-08-27 19:44:13 +00:00
|
|
|
break;
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
default:
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( wxT( "undefined DRAW command %c" ), aLine[0] );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( !newEntry->Load( aLine, 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" ),
|
|
|
|
GetChars( aErrorMsg ), aLine[0] );
|
2009-04-05 20:49:15 +00:00
|
|
|
SAFE_DELETE( newEntry );
|
|
|
|
|
|
|
|
/* Flush till end of draw section */
|
|
|
|
do
|
|
|
|
{
|
2010-06-10 18:43:12 +00:00
|
|
|
if( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) == NULL )
|
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;
|
|
|
|
}
|
2009-12-15 21:11:05 +00:00
|
|
|
} while( strncmp( aLine, "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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_COMPONENT::LoadField( char* aLine, 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
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
if( !field->Load( aLine, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_COMPONENT::LoadFootprints( FILE* aFile, char* aLine,
|
|
|
|
int* aLineNum, wxString& aErrorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-08-19 19:34:03 +00:00
|
|
|
while( true )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-06-10 18:43:12 +00:00
|
|
|
if( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) == NULL )
|
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
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( stricmp( aLine, "$ENDFPLIST" ) == 0 )
|
2009-08-19 19:34:03 +00:00
|
|
|
break;
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
m_FootprintList.Add( FROM_UTF8( aLine + 1 ) );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the component boundary box ( in user coordinates )
|
2011-02-27 19:54:01 +00:00
|
|
|
* aUnit = unit selection = 0, or 1..n
|
|
|
|
* aConvert = 0, 1 or 2
|
2009-12-15 21:11:05 +00:00
|
|
|
* If aUnit == 0, unit is not used
|
|
|
|
* if aConvert == 0 Convert is non used
|
2011-02-27 19:54:01 +00:00
|
|
|
* Invisible fields are not taken in account
|
2009-04-05 20:49:15 +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
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
BOOST_FOREACH( const LIB_DRAW_ITEM& item, drawings )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
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-02-27 19:54:01 +00:00
|
|
|
/* Return the component boundary box ( in user coordinates )
|
|
|
|
* aUnit = unit selection = 0, or 1..n
|
|
|
|
* aConvert = 0, 1 or 2
|
|
|
|
* If aUnit == 0, unit is not used
|
|
|
|
* if aConvert == 0 Convert is non used
|
|
|
|
* Fields are not take in account
|
|
|
|
**/
|
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
|
|
|
|
|
|
|
BOOST_FOREACH( const LIB_DRAW_ITEM& item, drawings )
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
LIB_DRAW_ITEM_LIST::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::GetFields( LIB_FIELD_LIST& 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.
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_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;
|
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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_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 )
|
|
|
|
{
|
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings )
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/*
|
2009-10-30 19:26:25 +00:00
|
|
|
* Read date and time of component in the format:
|
2009-04-05 20:49:15 +00:00
|
|
|
* "Ti yy/mm/jj hh:mm:ss"
|
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
bool LIB_COMPONENT::SaveDateAndTime( FILE* aFile )
|
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
|
|
|
|
2010-09-09 17:37:25 +00:00
|
|
|
if ( fprintf( aFile, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec ) < 0 )
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lit date et time de modif composant sous le format:
|
|
|
|
* "Ti yy/mm/jj hh:mm:ss"
|
|
|
|
*/
|
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;
|
|
|
|
char* text;
|
|
|
|
|
|
|
|
year = mon = day = hour = min = sec = 0;
|
2009-12-15 21:11:05 +00:00
|
|
|
text = strtok( aLine, " \r\t\n" );
|
2009-10-30 19:26:25 +00:00
|
|
|
text = strtok( NULL, " \r\t\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-09-09 17:37:25 +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 ) +
|
2009-04-05 20:49:15 +00:00
|
|
|
( ( hour & 31 ) << 12 ) + ( ( day & 31 ) << 17 ) +
|
|
|
|
( ( mon & 15 ) << 22 ) + ( ( year - 1990 ) << 26 );
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( const LIB_DRAW_ITEM& item, drawings )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings )
|
2009-10-05 17:52:41 +00:00
|
|
|
item.m_Flags = 0;
|
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
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
item.m_Selected = 0;
|
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
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
item.m_Selected = IS_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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
if( item.m_Selected == 0 )
|
2009-09-25 18:49:04 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
item.SetOffset( aOffset );
|
2009-10-05 17:52:41 +00:00
|
|
|
item.m_Flags = item.m_Selected = 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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings )
|
2009-10-05 17:52:41 +00:00
|
|
|
item.m_Flags = item.m_Selected = 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
|
|
|
{
|
2010-03-08 19:21:44 +00:00
|
|
|
LIB_DRAW_ITEM_LIST::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;
|
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
|
2010-03-08 19:21:44 +00:00
|
|
|
item->m_Selected = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item->m_Selected == 0 )
|
|
|
|
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();
|
|
|
|
for( unsigned ii = 0; ii < icnt; ii++ )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2010-02-20 14:49:14 +00:00
|
|
|
LIB_DRAW_ITEM& item = drawings[ii];
|
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 )
|
2010-03-08 19:21:44 +00:00
|
|
|
item.m_Selected = 0;
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( item.m_Selected == 0 )
|
2009-09-25 18:49:04 +00:00
|
|
|
continue;
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
item.m_Selected = 0;
|
|
|
|
LIB_DRAW_ITEM* newItem = item.GenCopy();
|
2009-09-25 18:49:04 +00:00
|
|
|
newItem->m_Selected = IS_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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
if( item.m_Selected == 0 )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
|
|
|
|
2010-03-01 19:52:40 +00:00
|
|
|
item.MirrorHorizontal( aCenter );
|
2009-10-05 17:52:41 +00:00
|
|
|
item.m_Flags = item.m_Selected = 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-06 13:52:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Locate a draw object.
|
|
|
|
*
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aUnit - Unit number of draw item.
|
|
|
|
* @param aConvert - Body style of draw item.
|
|
|
|
* @param aType - Draw object type, set to 0 to search for any type.
|
|
|
|
* @param aPoint - Coordinate for hit testing.
|
2009-10-06 13:52:43 +00:00
|
|
|
*
|
|
|
|
* @return LIB_DRAW_ITEM - Pointer the the draw object if found.
|
|
|
|
* Otherwise NULL.
|
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert,
|
|
|
|
KICAD_T aType, const wxPoint& aPoint )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_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
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
|
2010-10-20 20:24:26 +00:00
|
|
|
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.
|
2009-10-06 13:52:43 +00:00
|
|
|
* because this function uses DefaultTransformMatrix as orient/mirror matrix
|
|
|
|
* we temporary copy aTransMat in DefaultTransformMatrix
|
2009-10-19 19:00:47 +00:00
|
|
|
*/
|
2010-10-20 20:24:26 +00:00
|
|
|
LIB_DRAW_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
|
|
|
{
|
2009-12-17 11:03:26 +00:00
|
|
|
LIB_DRAW_ITEM_LIST::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();
|
|
|
|
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
|
|
|
{
|
2009-12-17 11:03:26 +00:00
|
|
|
LIB_DRAW_ITEM* newItem = drawings[ii].GenCopy();
|
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
|
|
|
{
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings )
|
2009-10-05 17:52:41 +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;
|
|
|
|
if( item.m_Convert == 1 )
|
|
|
|
{
|
|
|
|
LIB_DRAW_ITEM* newItem = item.GenCopy();
|
|
|
|
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
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM_LIST::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;
|
|
|
|
|
|
|
|
LIB_ALIAS_LIST::const_iterator it;
|
|
|
|
|
|
|
|
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
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
/* Remove names in the current component that are not in the new alias list. */
|
|
|
|
LIB_ALIAS_LIST::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." ) );
|
|
|
|
|
|
|
|
LIB_ALIAS_LIST::iterator it;
|
|
|
|
|
|
|
|
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;
|
|
|
|
LIB_ALIAS_LIST::iterator it = find( m_aliases.begin(), m_aliases.end(), aAlias );
|
|
|
|
|
|
|
|
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 ) );
|
|
|
|
}
|