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-04-05 20:49:15 +00:00
|
|
|
/* Basic class for library component description
|
2008-12-31 09:27:19 +00:00
|
|
|
* Not directly used
|
|
|
|
* Used to create the 2 derived classes :
|
2009-09-18 14:56:05 +00:00
|
|
|
* - LIB_ALIAS
|
|
|
|
* - LIB_COMPONENT
|
2008-12-31 09:27:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/********************************************************************/
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIB_ENTRY::CMP_LIB_ENTRY( LibrEntryType type, const wxString& name,
|
|
|
|
CMP_LIBRARY* lib ) :
|
2008-12-31 09:27:19 +00:00
|
|
|
EDA_BaseStruct( LIBCOMPONENT_STRUCT_TYPE )
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
Type = type;
|
2008-12-31 09:27:19 +00:00
|
|
|
m_Name.m_FieldId = VALUE;
|
2009-06-18 13:30:52 +00:00
|
|
|
m_Name.SetParent( this );
|
2009-09-18 14:56:05 +00:00
|
|
|
m_Name.m_Text = name;
|
|
|
|
m_lib = lib;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
CMP_LIB_ENTRY::CMP_LIB_ENTRY( CMP_LIB_ENTRY& entry, CMP_LIBRARY* lib ) :
|
2009-09-25 18:49:04 +00:00
|
|
|
EDA_BaseStruct( entry )
|
|
|
|
{
|
|
|
|
Type = entry.Type;
|
|
|
|
m_Name = entry.m_Name;
|
|
|
|
m_Doc = entry.m_Doc;
|
|
|
|
m_KeyWord = entry.m_KeyWord;
|
|
|
|
m_DocFile = entry.m_DocFile;
|
|
|
|
m_Options = entry.m_Options;
|
|
|
|
m_lib = lib;
|
|
|
|
m_Name.SetParent( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
if( m_lib != NULL )
|
|
|
|
return m_lib->GetName();
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
if( m_Doc.IsEmpty() && m_KeyWord.IsEmpty() && m_DocFile.IsEmpty() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* Generation des lignes utiles */
|
|
|
|
if( fprintf( aFile, "#\n$CMP %s\n", CONV_TO_UTF8( m_Name.m_Text ) ) < 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( ! m_Doc.IsEmpty()
|
|
|
|
&& fprintf( aFile, "D %s\n", CONV_TO_UTF8( m_Doc ) ) < 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( ! m_KeyWord.IsEmpty()
|
|
|
|
&& fprintf( aFile, "K %s\n", CONV_TO_UTF8( m_KeyWord ) ) < 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( ! m_DocFile.IsEmpty()
|
|
|
|
&& fprintf( aFile, "F %s\n", CONV_TO_UTF8( m_DocFile ) ) < 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( fprintf( aFile, "$ENDCMP\n" ) < 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CMP_LIB_ENTRY::operator==( const wxChar* name ) const
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
|
|
|
return m_Name.m_Text.CmpNoCase( name ) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
bool operator<( const CMP_LIB_ENTRY& item1, const CMP_LIB_ENTRY& item2 )
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2009-09-02 18:12:45 +00:00
|
|
|
return item1.m_Name.m_Text.CmpNoCase( item2.m_Name.m_Text ) < 0;
|
2009-08-27 11:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
int LibraryEntryCompare( const CMP_LIB_ENTRY* LE1, const CMP_LIB_ENTRY* LE2 )
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
|
|
|
return LE1->m_Name.m_Text.CmpNoCase( LE2->m_Name.m_Text );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-09-18 14:56:05 +00:00
|
|
|
LIB_ALIAS::LIB_ALIAS( const wxString& name, LIB_COMPONENT* root,
|
|
|
|
CMP_LIBRARY* lib ) :
|
|
|
|
CMP_LIB_ENTRY( ALIAS, name, lib )
|
|
|
|
{
|
|
|
|
wxASSERT( root != NULL && root->Type == ROOT );
|
|
|
|
|
|
|
|
m_root = root;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
LIB_ALIAS::LIB_ALIAS( LIB_ALIAS& alias, CMP_LIBRARY* lib ) :
|
2009-09-25 18:49:04 +00:00
|
|
|
CMP_LIB_ENTRY( alias )
|
|
|
|
{
|
|
|
|
m_root = alias.m_root;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_ALIAS::~LIB_ALIAS()
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
void LIB_ALIAS::SetComponent( LIB_COMPONENT* root )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
wxASSERT( root != NULL && root->Type == ROOT );
|
|
|
|
|
|
|
|
m_root = root;
|
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-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT::LIB_COMPONENT( const wxString& name, CMP_LIBRARY* lib ) :
|
|
|
|
CMP_LIB_ENTRY( ROOT, name, lib )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
m_LastDate = 0;
|
|
|
|
m_UnitCount = 1;
|
|
|
|
m_TextInside = 40;
|
|
|
|
m_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;
|
|
|
|
m_Prefix.m_FieldId = REFERENCE;
|
2009-06-18 13:30:52 +00:00
|
|
|
m_Prefix.SetParent( this );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& component, CMP_LIBRARY* lib ) :
|
2009-09-25 18:49:04 +00:00
|
|
|
CMP_LIB_ENTRY( component, lib )
|
|
|
|
{
|
|
|
|
LIB_DRAW_ITEM* newItem;
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD* oldField;
|
|
|
|
LIB_FIELD* newField;
|
2009-09-25 18:49:04 +00:00
|
|
|
|
|
|
|
m_Prefix = component.m_Prefix;
|
|
|
|
m_AliasList = component.m_AliasList;
|
|
|
|
m_FootprintList = component.m_FootprintList;
|
|
|
|
m_UnitCount = component.m_UnitCount;
|
|
|
|
m_UnitSelectionLocked = component.m_UnitSelectionLocked;
|
|
|
|
m_TextInside = component.m_TextInside;
|
|
|
|
m_DrawPinNum = component.m_DrawPinNum;
|
|
|
|
m_DrawPinName = component.m_DrawPinName;
|
|
|
|
m_LastDate = component.m_LastDate;
|
|
|
|
|
|
|
|
m_Prefix.SetParent( this );
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& oldItem, component.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-10-05 17:52:41 +00:00
|
|
|
m_Drawings.push_back( newItem );
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( oldField = component.m_Fields; oldField != NULL;
|
|
|
|
oldField = oldField->Next() )
|
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
newField = (LIB_FIELD*) oldField->GenCopy();
|
2009-09-25 18:49:04 +00:00
|
|
|
newField->SetParent( this );
|
|
|
|
m_Fields.PushBack( newField );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT::~LIB_COMPONENT()
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
void LIB_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* dc,
|
|
|
|
const wxPoint& offset, int multi,
|
|
|
|
int convert, int drawMode, int color,
|
|
|
|
const int transformMatrix[2][2],
|
|
|
|
bool showPinText, bool drawFields,
|
|
|
|
bool onlySelected )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
BASE_SCREEN* screen = panel->GetScreen();
|
2009-09-04 18:57:37 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( dc, drawMode );
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& drawItem, m_Drawings )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
if( onlySelected && 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-10-05 17:52:41 +00:00
|
|
|
if( multi && drawItem.m_Unit && ( drawItem.m_Unit != multi ) )
|
2009-09-04 18:57:37 +00:00
|
|
|
continue;
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( convert && drawItem.m_Convert && ( drawItem.m_Convert != convert ) )
|
2009-09-04 18:57:37 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( drawItem.Type() == COMPONENT_PIN_DRAW_TYPE )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
drawItem.Draw( panel, dc, offset, color, drawMode, &showPinText,
|
|
|
|
transformMatrix );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool force_nofill =
|
|
|
|
( screen->m_IsPrinting
|
2009-10-05 17:52:41 +00:00
|
|
|
&& drawItem.m_Fill == FILLED_WITH_BG_BODYCOLOR
|
2009-09-04 18:57:37 +00:00
|
|
|
&& GetGRForceBlackPenState() );
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
drawItem.Draw( panel, dc, offset, color, drawMode,
|
|
|
|
(void*) force_nofill, transformMatrix );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( drawFields )
|
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD* Field;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The reference designator field is a special case for naming
|
2009-09-04 18:57:37 +00:00
|
|
|
* convention.
|
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
wxString fieldText = m_Prefix.GetFullText( multi );
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( !( onlySelected && m_Prefix.m_Selected == 0 ) )
|
|
|
|
m_Prefix.Draw( panel, dc, offset, color, drawMode, &fieldText,
|
|
|
|
transformMatrix );
|
|
|
|
|
|
|
|
if( !( onlySelected && m_Name.m_Selected == 0 ) )
|
|
|
|
m_Name.Draw( panel, dc, offset, color, drawMode, NULL,
|
|
|
|
transformMatrix );
|
2009-09-04 18:57:37 +00:00
|
|
|
|
|
|
|
for( Field = m_Fields; Field != NULL; Field = Field->Next() )
|
|
|
|
{
|
2009-10-06 13:19:40 +00:00
|
|
|
if( onlySelected && Field->m_Selected == 0 )
|
2009-09-25 18:49:04 +00:00
|
|
|
continue;
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
Field->Draw( panel, dc, offset, color, drawMode, NULL,
|
|
|
|
transformMatrix );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 17:48:40 +00:00
|
|
|
/* Enable this to draw the anchor of the component. */
|
|
|
|
#if 0
|
2009-09-04 18:57:37 +00:00
|
|
|
int len = panel->GetScreen()->Unscale( 3 );
|
|
|
|
GRLine( &panel->m_ClipBox, dc, offset.x, offset.y - len, offset.x,
|
|
|
|
offset.y + len, 0, color );
|
|
|
|
GRLine( &panel->m_ClipBox, dc, offset.x - len, offset.y, offset.x + len,
|
|
|
|
offset.y, 0, color );
|
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-10-01 14:17:47 +00:00
|
|
|
EDA_Rect bBox = GetBoundaryBox( multi, convert );
|
2009-09-04 18:57:37 +00:00
|
|
|
GRRect( &panel->m_ClipBox, dc, bBox.GetOrigin().x, bBox.GetOrigin().y,
|
|
|
|
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
void LIB_COMPONENT::Plot( PLOTTER* plotter, int unit, int convert,
|
|
|
|
const wxPoint& offset, const int transform[2][2] )
|
|
|
|
{
|
|
|
|
wxASSERT( plotter != NULL );
|
|
|
|
|
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
|
|
|
|
{
|
|
|
|
if( unit && item.m_Unit && ( item.m_Unit != unit ) )
|
|
|
|
continue;
|
|
|
|
if( convert && item.m_Convert && ( item.m_Convert != convert ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
|
|
|
|
bool fill = plotter->get_color_mode();
|
|
|
|
|
|
|
|
item.Plot( plotter, offset, fill, transform );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_ITEM* item,
|
2009-09-18 14:56:05 +00:00
|
|
|
WinEDA_DrawPanel* panel,
|
|
|
|
wxDC* dc )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
|
|
|
wxASSERT( item != NULL );
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
LIB_DRAW_ITEM_LIST::iterator i;
|
2009-09-04 18:57:37 +00:00
|
|
|
|
|
|
|
if( dc != NULL )
|
|
|
|
item->Draw( panel, dc, 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-09-29 18:38:21 +00:00
|
|
|
if( item->Type() != COMPONENT_FIELD_DRAW_TYPE )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
for( i = m_Drawings.begin(); i < m_Drawings.end(); i++ )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
if( *i == item )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
m_Drawings.erase( i );
|
2009-09-29 18:38:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD* field;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
|
|
|
for( field = m_Fields; field != NULL; field = field->Next() )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-09-29 18:38:21 +00:00
|
|
|
if( field == item )
|
|
|
|
{
|
|
|
|
m_Fields.Remove( field );
|
|
|
|
delete field;
|
|
|
|
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-09-29 18:38:21 +00:00
|
|
|
void LIB_COMPONENT::AddDrawItem( LIB_DRAW_ITEM* item )
|
|
|
|
{
|
|
|
|
wxASSERT( item != NULL );
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
m_Drawings.push_back( item );
|
|
|
|
m_Drawings.sort();
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LIB_DRAW_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_DRAW_ITEM* item,
|
|
|
|
KICAD_T type )
|
|
|
|
{
|
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-10-05 17:52:41 +00:00
|
|
|
if( m_Drawings.empty() )
|
|
|
|
return NULL;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-10-08 16:45:59 +00:00
|
|
|
if( item == NULL && type == TYPE_NOT_INIT ) // type is unspecified
|
2009-10-05 17:52:41 +00:00
|
|
|
return &m_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;
|
|
|
|
if( item )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-10-08 16:45:59 +00:00
|
|
|
for( ; idx < m_Drawings.size(); idx++ )
|
|
|
|
{
|
|
|
|
if( item == &m_Drawings[idx] )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
for( ; idx < m_Drawings.size(); idx++ )
|
|
|
|
{
|
|
|
|
if( type == TYPE_NOT_INIT || m_Drawings[ idx ].Type() == type )
|
|
|
|
return &m_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-10-14 19:43:31 +00:00
|
|
|
void LIB_COMPONENT::GetPins( LIB_PIN_LIST& pins, int unit, int convert )
|
|
|
|
{
|
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
|
|
|
|
{
|
|
|
|
if( item.Type() != COMPONENT_PIN_DRAW_TYPE ||
|
|
|
|
( unit && item.m_Unit != unit ) ||
|
|
|
|
( convert && item.m_Convert != convert ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pins.push_back( (LIB_PIN*) &item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/**
|
|
|
|
* Function Save
|
|
|
|
* writes the data structures for this object out to a FILE in "*.brd" format.
|
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
2009-09-18 14:56:05 +00:00
|
|
|
bool LIB_COMPONENT::Save( FILE* aFile )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD* Field;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
/* First line: it s a comment (component name for readers) */
|
2009-09-14 13:24:17 +00:00
|
|
|
if( fprintf( aFile, "#\n# %s\n#\n", CONV_TO_UTF8( m_Name.m_Text ) ) < 0 )
|
|
|
|
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-04-05 20:49:15 +00:00
|
|
|
if( (m_Name.m_Attributs & TEXT_NO_VISIBLE) == 0 )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
if( fprintf( aFile, " %s", CONV_TO_UTF8( m_Name.m_Text ) ) < 0 )
|
|
|
|
return false;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
if( fprintf( aFile, " ~%s", CONV_TO_UTF8( m_Name.m_Text ) ) < 0 )
|
|
|
|
return false;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( !m_Prefix.m_Text.IsEmpty() )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
if( fprintf( aFile, " %s", CONV_TO_UTF8( m_Prefix.m_Text ) ) < 0 )
|
|
|
|
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',
|
|
|
|
m_UnitCount, m_UnitSelectionLocked ? 'L' : 'F',
|
|
|
|
m_Options == ENTRY_POWER ? 'P' : 'N' ) < 0 )
|
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
if( !SaveDateAndTime( aFile ) || !m_Prefix.Save( aFile )
|
|
|
|
|| !m_Name.Save( aFile ) )
|
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
for( Field = m_Fields; Field != NULL; Field = Field->Next() )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
if( Field->m_Text.IsEmpty() && Field->m_Name.IsEmpty() )
|
|
|
|
continue;
|
2009-09-14 13:24:17 +00:00
|
|
|
if( !Field->Save( aFile ) )
|
|
|
|
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;
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < m_AliasList.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
if( fprintf( aFile, " %s", CONV_TO_UTF8( m_AliasList[ii] ) ) < 0 )
|
|
|
|
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;
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < m_FootprintList.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
if( fprintf( aFile, " %s\n",
|
|
|
|
CONV_TO_UTF8( m_FootprintList[ii] ) ) < 0 )
|
|
|
|
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-10-05 17:52:41 +00:00
|
|
|
if( !m_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-10-05 17:52:41 +00:00
|
|
|
m_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-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
|
2008-12-31 09:27:19 +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;
|
|
|
|
}
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
bool LIB_COMPONENT::Load( FILE* file, char* line, int* lineNum,
|
|
|
|
wxString& errorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int unused;
|
|
|
|
char* p;
|
|
|
|
char* name;
|
|
|
|
char* prefix = NULL;
|
|
|
|
|
|
|
|
bool Res;
|
|
|
|
wxString Msg;
|
|
|
|
|
|
|
|
p = strtok( line, " \t\r\n" );
|
|
|
|
|
|
|
|
if( strcmp( p, "DEF" ) != 0 )
|
|
|
|
{
|
2009-09-23 05:53:12 +00:00
|
|
|
errorMsg.Printf( wxT( "DEF command expected in line %d, aborted." ),
|
2009-04-05 20:49:15 +00:00
|
|
|
*lineNum );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read DEF line: */
|
|
|
|
char drawnum = 0;
|
|
|
|
char drawname = 0;
|
|
|
|
|
|
|
|
if( ( name = strtok( NULL, " \t\n" ) ) == NULL /* Part name: */
|
|
|
|
|| ( prefix = strtok( NULL, " \t\n" ) ) == NULL /* Prefix name: */
|
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* NumOfPins: */
|
|
|
|
|| sscanf( p, "%d", &unused ) != 1
|
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* TextInside: */
|
|
|
|
|| sscanf( p, "%d", &m_TextInside ) != 1
|
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* DrawNums: */
|
|
|
|
|| sscanf( p, "%c", &drawnum ) != 1
|
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* DrawNums: */
|
|
|
|
|| sscanf( p, "%c", &drawname ) != 1
|
|
|
|
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* m_UnitCount: */
|
|
|
|
|| sscanf( p, "%d", &m_UnitCount ) != 1 )
|
|
|
|
{
|
2009-09-28 16:14:45 +00:00
|
|
|
errorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ),
|
2009-04-05 20:49:15 +00:00
|
|
|
*lineNum );
|
|
|
|
while( GetLine( file, line, lineNum, 1024 ) )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
p = strtok( line, " \t\n" );
|
|
|
|
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-10-10 17:27:53 +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. */
|
|
|
|
strupper( name );
|
|
|
|
if( name[0] != '~' )
|
|
|
|
m_Name.m_Text = CONV_FROM_UTF8( name );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Name.m_Text = CONV_FROM_UTF8( &name[1] );
|
|
|
|
m_Name.m_Attributs |= TEXT_NO_VISIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strcmp( prefix, "~" ) == 0 )
|
|
|
|
{
|
|
|
|
m_Prefix.m_Text.Empty();
|
|
|
|
m_Prefix.m_Attributs |= TEXT_NO_VISIBLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_Prefix.m_Text = CONV_FROM_UTF8( prefix );
|
|
|
|
|
|
|
|
// 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' )
|
|
|
|
m_Options = ENTRY_POWER;
|
|
|
|
|
|
|
|
/* Read next lines */
|
|
|
|
while( GetLine( file, line, lineNum, 1024 ) )
|
|
|
|
{
|
|
|
|
p = strtok( line, " \t\n" );
|
|
|
|
|
|
|
|
/* This is the error flag ( if an error occurs, Res = FALSE) */
|
|
|
|
Res = true;
|
|
|
|
|
|
|
|
if( (line[0] == 'T') && (line[1] == 'i') )
|
|
|
|
Res = LoadDateAndTime( line );
|
|
|
|
else if( line[0] == 'F' )
|
2009-08-19 19:34:03 +00:00
|
|
|
Res = LoadField( line, Msg );
|
2009-04-05 20:49:15 +00:00
|
|
|
else if( strcmp( p, "ENDDEF" ) == 0 )
|
|
|
|
break;
|
|
|
|
else if( strcmp( p, "DRAW" ) == 0 )
|
2009-08-19 19:34:03 +00:00
|
|
|
Res = LoadDrawEntries( file, line, lineNum, 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" );
|
|
|
|
Res = LoadAliases( p, errorMsg );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else if( strncmp( p, "$FPLIST", 5 ) == 0 )
|
2009-08-19 19:34:03 +00:00
|
|
|
Res = LoadFootprints( file, line, lineNum, 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() )
|
|
|
|
errorMsg.Printf( wxT( "error occurred at line %d " ), *lineNum );
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2009-08-19 19:34:03 +00:00
|
|
|
errorMsg.Printf( wxT( "error <%s> occurred at line %d " ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( Msg ), *lineNum );
|
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-10-05 17:52:41 +00:00
|
|
|
m_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-09-18 14:56:05 +00:00
|
|
|
bool LIB_COMPONENT::LoadDrawEntries( FILE* f, char* line,
|
|
|
|
int* lineNum, wxString& errorMsg )
|
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 )
|
|
|
|
{
|
|
|
|
if( GetLine( f, line, lineNum, 1024 ) == NULL )
|
|
|
|
{
|
2009-08-19 19:34:03 +00:00
|
|
|
errorMsg = _( "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-04-05 20:49:15 +00:00
|
|
|
if( strncmp( line, "ENDDRAW", 7 ) == 0 )
|
2008-12-31 09:27:19 +00:00
|
|
|
break;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
newEntry = NULL;
|
|
|
|
|
|
|
|
switch( line[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-09-23 05:53:12 +00:00
|
|
|
errorMsg.Printf( wxT( "undefined DRAW command %c" ), line[0] );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-19 19:34:03 +00:00
|
|
|
if( !newEntry->Load( line, errorMsg ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-09-23 05:53:12 +00:00
|
|
|
errorMsg.Printf( wxT( "error <%s> in DRAW command %c" ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( errorMsg ), line[0] );
|
2009-04-05 20:49:15 +00:00
|
|
|
SAFE_DELETE( newEntry );
|
|
|
|
|
|
|
|
/* Flush till end of draw section */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if( GetLine( f, line, lineNum, 1024 ) == NULL )
|
|
|
|
{
|
2009-08-19 19:34:03 +00:00
|
|
|
errorMsg = _( "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;
|
|
|
|
}
|
|
|
|
} while( strncmp( line, "ENDDRAW", 7 ) != 0 );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
m_Drawings.push_back( newEntry );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
bool LIB_COMPONENT::LoadAliases( char* line, wxString& errorMsg )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-08-19 19:34:03 +00:00
|
|
|
char* text = strtok( line, " \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-09-18 14:56:05 +00:00
|
|
|
bool LIB_COMPONENT::LoadField( char* line, wxString& errorMsg )
|
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
|
|
|
|
|
|
|
if ( !field->Load( line, errorMsg ) )
|
|
|
|
{
|
|
|
|
SAFE_DELETE( field );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( field->m_FieldId == REFERENCE )
|
2009-08-19 19:34:03 +00:00
|
|
|
{
|
|
|
|
m_Prefix = *field;
|
|
|
|
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
|
|
|
{
|
|
|
|
m_Name = *field;
|
|
|
|
SAFE_DELETE( field );
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2009-08-19 19:34:03 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
m_Fields.PushBack( field );
|
2009-08-19 19:34:03 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
bool LIB_COMPONENT::LoadFootprints( FILE* file, char* line,
|
|
|
|
int* lineNum, wxString& errorMsg )
|
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
|
|
|
{
|
|
|
|
if( GetLine( file, line, lineNum, 1024 ) == NULL )
|
|
|
|
{
|
|
|
|
errorMsg = wxT( "file ended prematurely while loading footprints" );
|
|
|
|
return false;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-08-19 19:34:03 +00:00
|
|
|
if( stricmp( line, "$ENDFPLIST" ) == 0 )
|
|
|
|
break;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
m_FootprintList.Add( CONV_FROM_UTF8( line + 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 )
|
|
|
|
* The unit Unit, and the shape Convert are considered.
|
|
|
|
* If Unit == 0, Unit is not used
|
|
|
|
* if Convert == 0 Convert is non used
|
|
|
|
**/
|
|
|
|
/**********************************************************************/
|
2009-09-18 14:56:05 +00:00
|
|
|
EDA_Rect LIB_COMPONENT::GetBoundaryBox( int Unit, int Convert )
|
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-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
if( ( item.m_Unit > 0 ) && ( ( m_UnitCount > 1 ) && ( Unit > 0 )
|
|
|
|
&& ( Unit != 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
|
|
|
|
&& ( ( Convert > 0 ) && ( Convert != item.m_Convert ) ) )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
bBox.Merge( item.GetBoundingBox() );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
bBox.Merge( m_Name.GetBoundingBox() );
|
|
|
|
bBox.Merge( m_Prefix.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
|
|
|
{
|
|
|
|
// Init basic fields (Value = name in lib, and reference):
|
|
|
|
aFields[VALUE].Copy( &m_Name );
|
|
|
|
aFields[REFERENCE].Copy( &m_Prefix );
|
|
|
|
|
|
|
|
// Remove others fields:
|
2009-08-19 19:34:03 +00:00
|
|
|
m_Fields.DeleteAll();
|
2008-12-31 15:01:29 +00:00
|
|
|
|
|
|
|
for( unsigned ii = FOOTPRINT; ii < aFields.size(); ii++ )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
bool create = FALSE;
|
|
|
|
if( !aFields[ii].m_Text.IsEmpty() )
|
2009-10-10 17:27:53 +00:00
|
|
|
create = true;
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !aFields[ii].m_Name.IsEmpty()
|
|
|
|
&& ( aFields[ii].m_Name != ReturnDefaultFieldName( ii ) ) )
|
2009-10-10 17:27:53 +00:00
|
|
|
create = true;
|
2009-04-05 20:49:15 +00:00
|
|
|
if( create )
|
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD*Field = new LIB_FIELD( this, ii );
|
2009-04-05 20:49:15 +00:00
|
|
|
aFields[ii].Copy( Field );
|
2009-08-19 19:34:03 +00:00
|
|
|
m_Fields.PushBack( Field );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* for a user field (FieldId >= FIELD1), if a field value is void,
|
2009-04-05 20:49:15 +00:00
|
|
|
* fill it with "~" because for a library component a void field is not
|
|
|
|
* a very good idea (we do not see anything...) and in schematic this
|
|
|
|
* text is like a void text and for non editable names, remove the name
|
|
|
|
* (set to the default name)
|
2008-12-31 15:01:29 +00:00
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
for( LIB_FIELD* Field = m_Fields; Field; Field = Field->Next() )
|
2008-12-31 15:01:29 +00:00
|
|
|
{
|
2009-06-18 13:30:52 +00:00
|
|
|
Field->SetParent( this );
|
2008-12-31 15:01:29 +00:00
|
|
|
if( Field->m_FieldId >= FIELD1 )
|
|
|
|
{
|
|
|
|
if( Field->m_Text.IsEmpty() )
|
|
|
|
Field->m_Text = wxT( "~" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Field->m_Name.Empty();
|
|
|
|
}
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lit date et time de modif composant sous le format:
|
|
|
|
* "Ti yy/mm/jj hh:mm:ss"
|
|
|
|
*/
|
2009-09-18 14:56:05 +00:00
|
|
|
bool LIB_COMPONENT::SaveDateAndTime( FILE* file )
|
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
|
|
|
|
|
|
|
if ( fprintf( file, "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-09-18 14:56:05 +00:00
|
|
|
bool LIB_COMPONENT::LoadDateAndTime( char* Line )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int year, mon, day, hour, min, sec;
|
|
|
|
char* text;
|
|
|
|
|
|
|
|
year = mon = day = hour = min = sec = 0;
|
|
|
|
text = strtok( Line, " \r\t\n" );
|
|
|
|
text = strtok( NULL, " \r\t\n" ); // text pointe donnees utiles
|
|
|
|
|
|
|
|
if (sscanf( Line, "%d/%d/%d %d:%d:%d",
|
|
|
|
&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-09-18 14:56:05 +00:00
|
|
|
void LIB_COMPONENT::SetOffset( const wxPoint& offset )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
m_Name.SetOffset( offset );
|
|
|
|
m_Prefix.SetOffset( offset );
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
for( LIB_FIELD* field = m_Fields; field != NULL; field = field->Next() )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
field->SetOffset( offset );
|
|
|
|
}
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
item.SetOffset( offset );
|
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-10-05 17:52:41 +00:00
|
|
|
m_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-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( const LIB_DRAW_ITEM& item, m_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-09-29 18:38:21 +00:00
|
|
|
void LIB_COMPONENT::ClearStatus( void )
|
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD* field;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
|
|
|
|
item.m_Flags = 0;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
|
|
|
m_Name.m_Flags = 0;
|
|
|
|
m_Prefix.m_Flags = 0;
|
|
|
|
|
|
|
|
for( field = m_Fields.GetFirst(); field != NULL; field = field->Next() )
|
|
|
|
field->m_Flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
int LIB_COMPONENT::SelectItems( EDA_Rect& rect, int unit, int convert,
|
|
|
|
bool editPinByPin )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
int ItemsCount = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_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-10-05 17:52:41 +00:00
|
|
|
if( ( item.m_Unit && item.m_Unit != unit )
|
|
|
|
|| ( item.m_Convert && item.m_Convert != convert ) )
|
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.
|
|
|
|
if( editPinByPin || m_UnitSelectionLocked
|
2009-10-05 17:52:41 +00:00
|
|
|
|| ( item.m_Convert && item.m_Convert != convert ) )
|
2009-09-25 18:49:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( item.Inside( rect ) )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
item.m_Selected = IS_SELECTED;
|
2009-09-25 18:49:04 +00:00
|
|
|
ItemsCount++;
|
|
|
|
}
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_Name.Inside( rect ) )
|
|
|
|
{
|
|
|
|
m_Name.m_Selected = IS_SELECTED;
|
|
|
|
ItemsCount++;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_Prefix.Inside( rect ) )
|
|
|
|
{
|
|
|
|
m_Prefix.m_Selected = IS_SELECTED;
|
|
|
|
ItemsCount++;
|
|
|
|
}
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
for( LIB_FIELD* field = m_Fields.GetFirst(); field != NULL;
|
2009-09-25 18:49:04 +00:00
|
|
|
field = field->Next() )
|
|
|
|
{
|
|
|
|
if( field->Inside( rect ) )
|
|
|
|
{
|
|
|
|
field->m_Selected = IS_SELECTED;
|
|
|
|
ItemsCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ItemsCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_COMPONENT::MoveSelectedItems( const wxPoint& offset )
|
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD* field;
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_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.SetOffset( offset );
|
|
|
|
item.m_Flags = item.m_Selected = 0;
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Name.m_Selected )
|
|
|
|
{
|
|
|
|
m_Name.SetOffset( offset );
|
|
|
|
m_Name.m_Flags = m_Name.m_Selected = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Prefix.m_Selected )
|
|
|
|
{
|
|
|
|
m_Prefix.SetOffset( offset );
|
|
|
|
m_Prefix.m_Flags = m_Prefix.m_Selected = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( field = m_Fields.GetFirst(); field != NULL; field = field->Next() )
|
|
|
|
{
|
|
|
|
if( field->m_Selected )
|
|
|
|
{
|
|
|
|
field->SetOffset( offset );
|
|
|
|
field->m_Flags = field->m_Selected = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
m_Drawings.sort();
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_COMPONENT::ClearSelectedItems( void )
|
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD* field;
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
|
|
|
|
item.m_Flags = item.m_Selected = 0;
|
2009-09-25 18:49:04 +00:00
|
|
|
|
|
|
|
m_Name.m_Flags = m_Name.m_Selected = 0;
|
|
|
|
m_Prefix.m_Flags = m_Prefix.m_Selected = 0;
|
|
|
|
|
|
|
|
for( field = m_Fields.GetFirst(); field != NULL; field = field->Next() )
|
|
|
|
field->m_Flags = field->m_Selected = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_COMPONENT::DeleteSelectedItems( void )
|
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
LIB_DRAW_ITEM_LIST::iterator i = m_Drawings.begin();
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
while( i != m_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
|
|
|
|
i = m_Drawings.erase( i );
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_COMPONENT::CopySelectedItems( const wxPoint& offset )
|
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_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-10-05 17:52:41 +00:00
|
|
|
m_Drawings.push_back( newItem );
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MoveSelectedItems( offset );
|
2009-10-05 17:52:41 +00:00
|
|
|
m_Drawings.sort();
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-09-29 18:38:21 +00:00
|
|
|
|
|
|
|
void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& center )
|
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD* field;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_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-10-05 17:52:41 +00:00
|
|
|
item.SetOffset( center );
|
|
|
|
item.m_Flags = item.m_Selected = 0;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Name.m_Selected )
|
|
|
|
{
|
|
|
|
m_Name.SetOffset( center );
|
|
|
|
m_Name.m_Flags = m_Name.m_Selected = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Prefix.m_Selected )
|
|
|
|
{
|
|
|
|
m_Prefix.SetOffset( center );
|
|
|
|
m_Prefix.m_Flags = m_Prefix.m_Selected = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( field = m_Fields.GetFirst(); field != NULL; field = field->Next() )
|
|
|
|
{
|
|
|
|
if( field->m_Selected )
|
|
|
|
{
|
|
|
|
field->SetOffset( center );
|
|
|
|
field->m_Flags = field->m_Selected = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
m_Drawings.sort();
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-06 13:52:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Locate a draw object.
|
|
|
|
*
|
|
|
|
* @param unit - Unit number of draw item.
|
|
|
|
* @param convert - Body style of draw item.
|
|
|
|
* @param type - Draw object type, set to 0 to search for any type.
|
|
|
|
* @param pt - Coordinate for hit testing.
|
|
|
|
*
|
|
|
|
* @return LIB_DRAW_ITEM - Pointer the the draw object if found.
|
|
|
|
* Otherwise NULL.
|
|
|
|
*/
|
2009-09-29 18:38:21 +00:00
|
|
|
LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int unit, int convert,
|
|
|
|
KICAD_T type, const wxPoint& pt )
|
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD* field;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
if( ( unit && item.m_Unit && ( unit != item.m_Unit) )
|
|
|
|
|| ( convert && item.m_Convert && ( convert != item.m_Convert ) )
|
|
|
|
|| ( ( item.Type() != type ) && ( type != TYPE_NOT_INIT ) ) )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( item.HitTest( pt ) )
|
|
|
|
return &item;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( type == COMPONENT_FIELD_DRAW_TYPE || type == TYPE_NOT_INIT )
|
|
|
|
{
|
|
|
|
if( m_Name.HitTest( pt ) )
|
|
|
|
return &m_Name;
|
|
|
|
if( m_Prefix.HitTest( pt ) )
|
|
|
|
return &m_Prefix;
|
|
|
|
|
|
|
|
for( field = m_Fields.GetFirst(); field != NULL; field = field->Next() )
|
|
|
|
{
|
|
|
|
if( field->HitTest( pt ) )
|
|
|
|
return field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
* @param aTransMat = the transform matrix
|
|
|
|
*
|
|
|
|
* @return LIB_DRAW_ITEM - Pointer the the draw object if found.
|
|
|
|
* Otherwise NULL.
|
|
|
|
*/
|
|
|
|
LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int unit, int convert,
|
|
|
|
KICAD_T type, const wxPoint& pt, const int aTransMat[2][2] )
|
|
|
|
{
|
|
|
|
/* we use LocateDrawItem( int unit, int convert, KICAD_T type, const wxPoint& pt )
|
|
|
|
* to search items.
|
|
|
|
* because this function uses DefaultTransformMatrix as orient/mirror matrix
|
|
|
|
* we temporary copy aTransMat in DefaultTransformMatrix
|
|
|
|
*/
|
|
|
|
LIB_DRAW_ITEM * item;
|
|
|
|
int matrix[2][2];
|
|
|
|
for ( int ii =0; ii<2;ii++ )
|
|
|
|
{
|
|
|
|
for ( int jj =0; jj<2;jj++ )
|
|
|
|
{
|
|
|
|
matrix[ii][jj] = aTransMat[ii][jj];
|
|
|
|
EXCHG(matrix[ii][jj], DefaultTransformMatrix[ii][jj]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
item = LocateDrawItem( unit, convert, type, pt );
|
|
|
|
//Restore matrix
|
|
|
|
for ( int ii =0; ii<2;ii++ )
|
|
|
|
{
|
|
|
|
for ( int jj =0; jj<2;jj++ )
|
|
|
|
{
|
|
|
|
EXCHG(matrix[ii][jj], DefaultTransformMatrix[ii][jj]);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
void LIB_COMPONENT::SetPartCount( int count )
|
|
|
|
{
|
|
|
|
LIB_DRAW_ITEM_LIST::iterator i;
|
|
|
|
|
|
|
|
if( m_UnitCount == count )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( count < m_UnitCount )
|
|
|
|
{
|
|
|
|
i = m_Drawings.begin();
|
|
|
|
|
|
|
|
while( i != m_Drawings.end() )
|
|
|
|
{
|
|
|
|
if( i->m_Unit > count )
|
|
|
|
i = m_Drawings.erase( i );
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int prevCount = m_UnitCount;
|
|
|
|
|
|
|
|
for( i = m_Drawings.begin(); i != m_Drawings.end(); i++ )
|
|
|
|
{
|
|
|
|
if( i->m_Unit != 1 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for( int j = prevCount + 1; j <= count; j++ )
|
|
|
|
{
|
|
|
|
LIB_DRAW_ITEM* newItem = i->GenCopy();
|
|
|
|
newItem->m_Unit = j;
|
|
|
|
m_Drawings.push_back( newItem );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Drawings.sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_UnitCount = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_COMPONENT::SetConversion( bool asConvert )
|
|
|
|
{
|
|
|
|
if( asConvert == HasConversion() )
|
|
|
|
return;
|
2009-10-10 17:27:53 +00:00
|
|
|
// Duplicate items to create the converted shape
|
2009-10-05 17:52:41 +00:00
|
|
|
if( asConvert )
|
|
|
|
{
|
|
|
|
|
|
|
|
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
|
|
|
|
{
|
|
|
|
/* 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;
|
|
|
|
m_Drawings.push_back( newItem );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
// Delete converted shape items becuase the converted shape does not exist
|
2009-10-05 17:52:41 +00:00
|
|
|
LIB_DRAW_ITEM_LIST::iterator i = m_Drawings.begin();
|
|
|
|
|
|
|
|
while( i != m_Drawings.end() )
|
|
|
|
{
|
|
|
|
if( i->m_Convert > 1 )
|
|
|
|
i = m_Drawings.erase( i );
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|