2008-12-31 09:27:19 +00:00
|
|
|
/**********************************************************/
|
2009-04-05 20:49:15 +00:00
|
|
|
/* lib_entry.cpp */
|
2008-12-31 09:27:19 +00:00
|
|
|
/**********************************************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "confirm.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"
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
|
|
|
#include "class_libentry.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
|
|
|
|
|
|
|
/*********************/
|
2009-09-18 14:56:05 +00:00
|
|
|
/* class CMP_LIB_ENTRY */
|
2008-12-31 09:27:19 +00:00
|
|
|
/*********************/
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
CMP_LIB_ENTRY::CMP_LIB_ENTRY( LibrEntryType aType, const wxString& aName,
|
|
|
|
CMP_LIBRARY* aLibrary ) :
|
2008-12-31 09:27:19 +00:00
|
|
|
EDA_BaseStruct( LIBCOMPONENT_STRUCT_TYPE )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
type = aType;
|
|
|
|
name = aName;
|
|
|
|
library = aLibrary;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
CMP_LIB_ENTRY::CMP_LIB_ENTRY( CMP_LIB_ENTRY& aEntry, CMP_LIBRARY* aLibrary ) :
|
|
|
|
EDA_BaseStruct( aEntry )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
type = aEntry.type;
|
|
|
|
name = aEntry.name;
|
|
|
|
description = aEntry.description;
|
|
|
|
keyWords = aEntry.keyWords;
|
|
|
|
docFileName = aEntry.docFileName;
|
|
|
|
options = aEntry.options;
|
|
|
|
library = aLibrary;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIB_ENTRY::~CMP_LIB_ENTRY()
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
wxString CMP_LIB_ENTRY::GetLibraryName()
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( library != NULL )
|
|
|
|
return library->GetName();
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
return wxString( _( "none" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
bool CMP_LIB_ENTRY::SaveDoc( FILE* aFile )
|
|
|
|
{
|
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;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( fprintf( aFile, "#\n$CMP %s\n", CONV_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()
|
|
|
|
&& fprintf( aFile, "D %s\n", CONV_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()
|
|
|
|
&& fprintf( aFile, "K %s\n", CONV_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()
|
|
|
|
&& fprintf( aFile, "F %s\n", CONV_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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool CMP_LIB_ENTRY::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
bool operator<( const CMP_LIB_ENTRY& aItem1, const CMP_LIB_ENTRY& 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
int LibraryEntryCompare( const CMP_LIB_ENTRY* aItem1, const CMP_LIB_ENTRY* 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
/*******************************/
|
2009-09-18 14:56:05 +00:00
|
|
|
/* class LIB_ALIAS */
|
2008-12-31 09:27:19 +00:00
|
|
|
/*******************************/
|
|
|
|
|
|
|
|
/* Class to define an alias of a component
|
2009-04-05 20:49:15 +00:00
|
|
|
* An alias uses the component definition (graphic, pins...)
|
2008-12-31 09:27:19 +00:00
|
|
|
* but has its own name and documentation.
|
2009-04-05 20:49:15 +00:00
|
|
|
* Therefore, when the component is modified, alias of this component are
|
|
|
|
* modified.
|
2008-12-31 09:27:19 +00:00
|
|
|
* This is a simple method to create components with differs very few
|
|
|
|
* (like 74LS00, 74HC00 ... and many op amps )
|
|
|
|
*/
|
|
|
|
|
2009-12-22 14:08:24 +00:00
|
|
|
LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent,
|
2009-12-15 21:11:05 +00:00
|
|
|
CMP_LIBRARY* aLibrary ) :
|
|
|
|
CMP_LIB_ENTRY( ALIAS, aName, aLibrary )
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
2009-12-22 14:08:24 +00:00
|
|
|
wxASSERT( aRootComponent != NULL && aRootComponent->isComponent() );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-12-22 14:08:24 +00:00
|
|
|
root = aRootComponent;
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_ALIAS::LIB_ALIAS( LIB_ALIAS& aAlias, CMP_LIBRARY* aLibrary ) :
|
|
|
|
CMP_LIB_ENTRY( aAlias )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
root = aAlias.root;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_ALIAS::~LIB_ALIAS()
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_ALIAS::SetComponent( LIB_COMPONENT* aComponent )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aComponent != NULL && aComponent->isComponent() );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
root = aComponent;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************/
|
2009-09-18 14:56:05 +00:00
|
|
|
/* class LIB_COMPONENT */
|
2008-12-31 09:27:19 +00:00
|
|
|
/********************************/
|
|
|
|
|
|
|
|
/* This is a standard component (in library)
|
|
|
|
*/
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_COMPONENT::LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary ) :
|
|
|
|
CMP_LIB_ENTRY( ROOT, aName, aLibrary )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
m_LastDate = 0;
|
2009-12-15 21:11:05 +00:00
|
|
|
unitCount = 1;
|
2009-09-14 13:24:17 +00:00
|
|
|
m_TextInside = 40;
|
2009-12-15 21:11:05 +00:00
|
|
|
options = ENTRY_NORMAL;
|
2008-12-31 09:27:19 +00:00
|
|
|
m_UnitSelectionLocked = FALSE;
|
2009-09-14 13:24:17 +00:00
|
|
|
m_DrawPinNum = 1;
|
|
|
|
m_DrawPinName = 1;
|
2009-10-21 20:02:25 +00:00
|
|
|
|
|
|
|
/* The minimum requirements for a component are a value and a reference
|
|
|
|
* designator field.
|
|
|
|
*/
|
|
|
|
LIB_FIELD* value = new LIB_FIELD( this, VALUE );
|
2009-12-15 21:11:05 +00:00
|
|
|
value->m_Text = aName;
|
|
|
|
drawings.push_back( value );
|
|
|
|
drawings.push_back( new LIB_FIELD( this, REFERENCE ) );
|
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 ) :
|
|
|
|
CMP_LIB_ENTRY( aComponent, aLibrary )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
|
|
|
LIB_DRAW_ITEM* newItem;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
m_AliasList = aComponent.m_AliasList;
|
|
|
|
m_FootprintList = aComponent.m_FootprintList;
|
|
|
|
unitCount = aComponent.unitCount;
|
|
|
|
m_UnitSelectionLocked = aComponent.m_UnitSelectionLocked;
|
|
|
|
m_TextInside = aComponent.m_TextInside;
|
|
|
|
m_DrawPinNum = aComponent.m_DrawPinNum;
|
|
|
|
m_DrawPinName = aComponent.m_DrawPinName;
|
|
|
|
m_LastDate = aComponent.m_LastDate;
|
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
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
if( ( oldItem.m_Flags & IS_NEW ) != 0 )
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT::~LIB_COMPONENT()
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDc,
|
|
|
|
const wxPoint& aOffset, int aMulti,
|
|
|
|
int aConvert, int aDrawMode, int aColor,
|
|
|
|
const int aTransformMatrix[2][2],
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( !aDrawFields && drawItem.Type() == COMPONENT_FIELD_DRAW_TYPE )
|
2009-10-21 20:02:25 +00:00
|
|
|
continue;
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( drawItem.Type() == COMPONENT_PIN_DRAW_TYPE )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode,
|
|
|
|
(void*) aShowPinText, aTransformMatrix );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
2009-10-21 20:02:25 +00:00
|
|
|
else if( drawItem.Type() == COMPONENT_FIELD_DRAW_TYPE )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode,
|
|
|
|
(void*) NULL, aTransformMatrix );
|
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
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
bool forceNoFill = ( screen->m_IsPrinting
|
|
|
|
&& drawItem.m_Fill == FILLED_WITH_BG_BODYCOLOR
|
|
|
|
&& GetGRForceBlackPenState() );
|
2009-12-15 21:11:05 +00:00
|
|
|
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode,
|
|
|
|
(void*) forceNoFill, aTransformMatrix );
|
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
|
2009-12-15 21:11:05 +00:00
|
|
|
int len = aPanel->GetScreen()->Unscale( 3 );
|
|
|
|
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
|
2009-12-15 21:11:05 +00:00
|
|
|
EDA_Rect bBox = GetBoundaryBox( aMulti, aConvert );
|
|
|
|
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,
|
|
|
|
const wxPoint& aOffset, const int aTransform[2][2] )
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_ITEM* aItem,
|
|
|
|
WinEDA_DrawPanel* 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
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
/* Value and reference fields cannot be removed. */
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aItem->Type() == COMPONENT_FIELD_DRAW_TYPE )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_FIELD* field = (LIB_FIELD*)aItem;
|
2009-10-21 20:02:25 +00:00
|
|
|
|
|
|
|
if( field->m_FieldId == VALUE || field->m_FieldId == REFERENCE )
|
|
|
|
{
|
|
|
|
wxString fieldType = ( field->m_FieldId == VALUE ) ?
|
|
|
|
_( "value" ) : _( "reference" );
|
|
|
|
|
|
|
|
wxLogWarning( _( "An attempt was made to remove the %s field \
|
|
|
|
from component %s in library %s." ),
|
|
|
|
GetChars( fieldType ), GetChars( GetName() ),
|
|
|
|
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
|
|
|
if( aDc != NULL )
|
|
|
|
aItem->Draw( aPanel, aDc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
|
2009-09-14 13:24:17 +00:00
|
|
|
DefaultTransformMatrix );
|
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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.erase( i );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +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
|
|
|
{
|
2009-10-26 12:01:46 +00:00
|
|
|
if( item.Type() != COMPONENT_PIN_DRAW_TYPE ) // we search pins only
|
|
|
|
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++ )
|
|
|
|
{
|
|
|
|
wxASSERT( pinList[i]->Type() == COMPONENT_PIN_DRAW_TYPE );
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2009-10-21 20:02:25 +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) */
|
2009-10-21 20:02:25 +00:00
|
|
|
if( fprintf( aFile, "#\n# %s\n#\n", CONV_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-10-21 20:02:25 +00:00
|
|
|
if( ( value.m_Attributs & TEXT_NO_VISIBLE ) == 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
if( fprintf( aFile, " %s", CONV_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
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
if( fprintf( aFile, " ~%s", CONV_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
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
if( fprintf( aFile, " %s", CONV_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",
|
|
|
|
0, m_TextInside,
|
|
|
|
m_DrawPinNum ? 'Y' : 'N',
|
|
|
|
m_DrawPinName ? 'Y' : 'N',
|
2009-12-15 21:11:05 +00:00
|
|
|
unitCount, m_UnitSelectionLocked ? 'L' : 'F',
|
|
|
|
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 );
|
|
|
|
|
|
|
|
for( i = 0; i < fields.size(); i++ )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
if( fields[i].m_Text.IsEmpty() && fields[i].m_Name.IsEmpty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
continue;
|
2009-10-21 20:02:25 +00:00
|
|
|
|
|
|
|
if( !fields[i].Save( aFile ) )
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
/* Save the alias list: a line starting by "ALIAS" */
|
|
|
|
if( m_AliasList.GetCount() != 0 )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
if( fprintf( aFile, "ALIAS" ) < 0 )
|
|
|
|
return false;
|
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
for( i = 0; i < m_AliasList.GetCount(); i++ )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
if( fprintf( aFile, " %s", CONV_TO_UTF8( m_AliasList[i] ) ) < 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
|
|
|
{
|
|
|
|
if( fprintf( aFile, " %s\n",
|
2009-10-21 20:02:25 +00:00
|
|
|
CONV_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
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
if( item.Type() == COMPONENT_FIELD_DRAW_TYPE )
|
|
|
|
continue;
|
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;
|
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +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 )
|
|
|
|
{
|
2009-12-15 21:11:05 +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: */
|
2009-04-05 20:49:15 +00:00
|
|
|
|| sscanf( p, "%d", &m_TextInside ) != 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
|
2009-12-15 21:11:05 +00:00
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* unitCount: */
|
|
|
|
|| sscanf( p, "%d", &unitCount ) != 1 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ),
|
|
|
|
*aLineNum );
|
|
|
|
while( GetLine( aFile, aLine, aLineNum, 1024 ) )
|
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;
|
|
|
|
}
|
|
|
|
|
2009-12-17 11:03:26 +00:00
|
|
|
// Ensure unitCount is >= 1 (could be read as 0 in old libraries)
|
|
|
|
if( unitCount < 1 )
|
|
|
|
unitCount = 1;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
m_DrawPinNum = ( drawnum == 'N' ) ? FALSE : true;
|
|
|
|
m_DrawPinName = ( 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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
name = value.m_Text = CONV_FROM_UTF8( componentName );
|
2009-10-21 20:02:25 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
name = value.m_Text = CONV_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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
reference.m_Text = CONV_FROM_UTF8( prefix );
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
// Copy optional infos
|
|
|
|
if( ( p = strtok( NULL, " \t\n" ) ) != NULL && *p == 'L' )
|
2009-10-10 17:27:53 +00:00
|
|
|
m_UnitSelectionLocked = true;
|
2009-04-05 20:49:15 +00:00
|
|
|
if( ( p = strtok( NULL, " \t\n" ) ) != NULL && *p == 'P' )
|
2009-12-15 21:11:05 +00:00
|
|
|
options = ENTRY_POWER;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
/* Read next lines */
|
2009-12-15 21:11:05 +00:00
|
|
|
while( GetLine( aFile, aLine, aLineNum, 1024 ) )
|
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 )
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( GetLine( aFile, aLine, aLineNum, 1024 ) == 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
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( GetLine( aFile, aLine, aLineNum, 1024 ) == NULL )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
aErrorMsg = wxT( "file ended prematurely while attempting \
|
2009-05-21 17:42:42 +00:00
|
|
|
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 )
|
|
|
|
{
|
|
|
|
m_AliasList.Add( CONV_FROM_UTF8( text ) );
|
|
|
|
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
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if ( !field->Load( aLine, aErrorMsg ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
SAFE_DELETE( field );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( field->m_FieldId == REFERENCE )
|
2009-08-19 19:34:03 +00:00
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
GetReferenceField() = *field;
|
2009-08-19 19:34:03 +00:00
|
|
|
SAFE_DELETE( field );
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else if ( field->m_FieldId == VALUE )
|
2009-08-19 19:34:03 +00:00
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
GetValueField() = *field;
|
2009-12-15 21:11:05 +00:00
|
|
|
name = field->m_Text;
|
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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( GetLine( aFile, aLine, aLineNum, 1024 ) == 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;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
m_FootprintList.Add( CONV_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 )
|
2009-12-15 21:11:05 +00:00
|
|
|
* The unit aUnit, and the shape aConvert are considered.
|
|
|
|
* If aUnit == 0, unit is not used
|
|
|
|
* if aConvert == 0 Convert is non used
|
2009-11-20 19:51:39 +00:00
|
|
|
* Invisible fields are not take in account
|
2009-04-05 20:49:15 +00:00
|
|
|
**/
|
|
|
|
/**********************************************************************/
|
2009-12-15 21:11:05 +00:00
|
|
|
EDA_Rect LIB_COMPONENT::GetBoundaryBox( int aUnit, int aConvert )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
EDA_Rect bBox( wxPoint( 0, 0 ), wxSize( 0, 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-04-05 20:49:15 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( ( item.m_Unit > 0 ) && ( ( unitCount > 1 ) && ( aUnit > 0 )
|
|
|
|
&& ( aUnit != item.m_Unit ) ) )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
2009-10-05 17:52:41 +00:00
|
|
|
if( item.m_Convert > 0
|
2009-12-15 21:11:05 +00:00
|
|
|
&& ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-11-20 19:51:39 +00:00
|
|
|
if ( ( item.Type() == COMPONENT_FIELD_DRAW_TYPE )
|
2009-12-15 21:11:05 +00:00
|
|
|
&& ( ( ( LIB_TEXT& ) item ).m_Attributs & TEXT_NO_VISIBLE ) )
|
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
|
|
|
|
|
|
|
|
|
|
|
/** Function SetFields
|
|
|
|
* initialize fields from a vector of fields
|
2009-10-08 13:19:28 +00:00
|
|
|
* @param aFields a std::vector <LIB_FIELD> to import.
|
2008-12-31 15:01:29 +00:00
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
void LIB_COMPONENT::SetFields( const std::vector <LIB_FIELD> aFields )
|
2008-12-31 15:01:29 +00:00
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
LIB_FIELD* field;
|
2008-12-31 15:01:29 +00:00
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
for( size_t i = 0; i < aFields.size(); i++ )
|
2008-12-31 15:01:29 +00:00
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
field = GetField( aFields[i].m_FieldId );
|
|
|
|
|
|
|
|
if( field )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
*field = aFields[i];
|
|
|
|
|
|
|
|
if( (int) i == VALUE )
|
2009-12-15 21:11:05 +00:00
|
|
|
name = field->m_Text;
|
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
|
|
|
|
|
|
|
/* If the field isn't set, don't add it to the component. */
|
|
|
|
if( aFields[i].m_Text.IsEmpty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
field = new LIB_FIELD( aFields[i] );
|
2009-12-15 21:11:05 +00:00
|
|
|
drawings.push_back( field );
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings )
|
2008-12-31 15:01:29 +00:00
|
|
|
{
|
2009-10-21 20:02:25 +00:00
|
|
|
if( item.Type() != COMPONENT_FIELD_DRAW_TYPE )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LIB_FIELD* field = ( LIB_FIELD* ) &item;
|
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
|
|
|
{
|
|
|
|
if( item.Type() != COMPONENT_FIELD_DRAW_TYPE )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LIB_FIELD* field = ( LIB_FIELD* ) &item;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( field->m_FieldId == aId )
|
2009-10-21 20:02:25 +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;
|
|
|
|
|
|
|
|
if( m_LastDate == 0 )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
sec = m_LastDate & 63;
|
2009-09-14 13:24:17 +00:00
|
|
|
min = ( m_LastDate >> 6 ) & 63;
|
|
|
|
hour = ( m_LastDate >> 12 ) & 31;
|
|
|
|
day = ( m_LastDate >> 17 ) & 31;
|
|
|
|
mon = ( m_LastDate >> 22 ) & 15;
|
|
|
|
year = ( m_LastDate >> 26 ) + 1990;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if ( fprintf( aFile, "Ti %d/%d/%d %d:%d:%d\n",
|
2009-09-14 13:24:17 +00:00
|
|
|
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
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if (sscanf( aLine, "%d/%d/%d %d:%d:%d",
|
2009-04-05 20:49:15 +00:00
|
|
|
&year, &mon, &day, &hour, &min, &sec ) != 6 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_LastDate = ( sec & 63 ) + ( ( min & 63 ) << 6 ) +
|
|
|
|
( ( 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 21:11:05 +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
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
if( item.Type() != COMPONENT_PIN_DRAW_TYPE )
|
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.
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aEditPinByPin || m_UnitSelectionLocked
|
|
|
|
|| ( 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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
LIB_DRAW_ITEM_LIST::iterator i = drawings.begin();
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
while( i != drawings.end() )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
if( i->m_Selected == 0 )
|
|
|
|
i++;
|
|
|
|
else
|
2009-12-15 21:11:05 +00:00
|
|
|
i = drawings.erase( i );
|
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
|
|
|
{
|
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-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
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
item.SetOffset( 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
|
|
|
|
2009-10-06 13:52:43 +00:00
|
|
|
/** Function HitTest (overlaid)
|
|
|
|
* @return true if the point aPosRef is near this object
|
|
|
|
* @param aPosRef = a wxPoint to test
|
|
|
|
* @param aThreshold = max distance to this object (usually the half
|
|
|
|
* thickness of a line)
|
2009-12-15 21:11:05 +00:00
|
|
|
* @param aTransform = the transform matrix
|
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, const int aTransform[2][2] )
|
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
|
|
|
*/
|
2009-10-06 13:52:43 +00:00
|
|
|
LIB_DRAW_ITEM * item;
|
|
|
|
int matrix[2][2];
|
2009-10-19 19:00:47 +00:00
|
|
|
for ( int ii = 0; ii < 2; ii++ )
|
2009-10-06 13:52:43 +00:00
|
|
|
{
|
2009-10-19 19:00:47 +00:00
|
|
|
for ( int jj = 0; jj < 2; jj++ )
|
2009-10-06 13:52:43 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
matrix[ii][jj] = aTransform[ii][jj];
|
2009-10-19 19:00:47 +00:00
|
|
|
EXCHG( matrix[ii][jj], DefaultTransformMatrix[ii][jj] );
|
2009-10-06 13:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-15 21:11:05 +00:00
|
|
|
item = LocateDrawItem( aUnit, aConvert, aType, aPoint );
|
2009-10-06 13:52:43 +00:00
|
|
|
//Restore matrix
|
2009-10-19 19:00:47 +00:00
|
|
|
for ( int ii = 0; ii < 2; ii++ )
|
2009-10-06 13:52:43 +00:00
|
|
|
{
|
2009-10-19 19:00:47 +00:00
|
|
|
for ( int jj = 0; jj < 2; jj++ )
|
2009-10-06 13:52:43 +00:00
|
|
|
{
|
2009-10-19 19:00:47 +00:00
|
|
|
EXCHG( matrix[ii][jj], DefaultTransformMatrix[ii][jj] );
|
2009-10-06 13:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( unitCount == aCount )
|
2009-10-05 17:52:41 +00:00
|
|
|
return;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aCount < 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
|
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
int prevCount = 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
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
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. */
|
|
|
|
if( item.Type() != COMPONENT_PIN_DRAW_TYPE )
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|