Commit 11bf0ad7 authored by stambaughw's avatar stambaughw

Merge component library draw item and field list.

* Use single list for component library draw item and fields to simplify
  component library object.
* Add field manipulation helper methods to component library object.
* Make component library draw item edit dialog sizable.
parent 6adf9163
......@@ -36,9 +36,7 @@ CMP_LIB_ENTRY::CMP_LIB_ENTRY( LibrEntryType type, const wxString& name,
EDA_BaseStruct( LIBCOMPONENT_STRUCT_TYPE )
{
Type = type;
m_Name.m_FieldId = VALUE;
m_Name.SetParent( this );
m_Name.m_Text = name;
m_Name = name;
m_lib = lib;
}
......@@ -53,7 +51,6 @@ CMP_LIB_ENTRY::CMP_LIB_ENTRY( CMP_LIB_ENTRY& entry, CMP_LIBRARY* lib ) :
m_DocFile = entry.m_DocFile;
m_Options = entry.m_Options;
m_lib = lib;
m_Name.SetParent( this );
}
......@@ -85,7 +82,7 @@ bool CMP_LIB_ENTRY::SaveDoc( FILE* aFile )
return true;
/* Generation des lignes utiles */
if( fprintf( aFile, "#\n$CMP %s\n", CONV_TO_UTF8( m_Name.m_Text ) ) < 0 )
if( fprintf( aFile, "#\n$CMP %s\n", CONV_TO_UTF8( m_Name ) ) < 0 )
return false;
if( ! m_Doc.IsEmpty()
......@@ -109,19 +106,19 @@ bool CMP_LIB_ENTRY::SaveDoc( FILE* aFile )
bool CMP_LIB_ENTRY::operator==( const wxChar* name ) const
{
return m_Name.m_Text.CmpNoCase( name ) == 0;
return m_Name.CmpNoCase( name ) == 0;
}
bool operator<( const CMP_LIB_ENTRY& item1, const CMP_LIB_ENTRY& item2 )
{
return item1.m_Name.m_Text.CmpNoCase( item2.m_Name.m_Text ) < 0;
return item1.GetName().CmpNoCase( item2.GetName() ) < 0;
}
int LibraryEntryCompare( const CMP_LIB_ENTRY* LE1, const CMP_LIB_ENTRY* LE2 )
{
return LE1->m_Name.m_Text.CmpNoCase( LE2->m_Name.m_Text );
return LE1->GetName().CmpNoCase( LE2->GetName() );
}
......@@ -184,8 +181,14 @@ LIB_COMPONENT::LIB_COMPONENT( const wxString& name, CMP_LIBRARY* lib ) :
m_UnitSelectionLocked = FALSE;
m_DrawPinNum = 1;
m_DrawPinName = 1;
m_Prefix.m_FieldId = REFERENCE;
m_Prefix.SetParent( this );
/* The minimum requirements for a component are a value and a reference
* designator field.
*/
LIB_FIELD* value = new LIB_FIELD( this, VALUE );
value->m_Text = name;
m_Drawings.push_back( value );
m_Drawings.push_back( new LIB_FIELD( this, REFERENCE ) );
}
......@@ -193,10 +196,7 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& component, CMP_LIBRARY* lib ) :
CMP_LIB_ENTRY( component, lib )
{
LIB_DRAW_ITEM* newItem;
LIB_FIELD* oldField;
LIB_FIELD* newField;
m_Prefix = component.m_Prefix;
m_AliasList = component.m_AliasList;
m_FootprintList = component.m_FootprintList;
m_UnitCount = component.m_UnitCount;
......@@ -206,8 +206,6 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& component, CMP_LIBRARY* lib ) :
m_DrawPinName = component.m_DrawPinName;
m_LastDate = component.m_LastDate;
m_Prefix.SetParent( this );
BOOST_FOREACH( LIB_DRAW_ITEM& oldItem, component.GetDrawItemList() )
{
if( ( oldItem.m_Flags & IS_NEW ) != 0 )
......@@ -217,14 +215,6 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& component, CMP_LIBRARY* lib ) :
newItem->SetParent( this );
m_Drawings.push_back( newItem );
}
for( oldField = component.m_Fields; oldField != NULL;
oldField = oldField->Next() )
{
newField = (LIB_FIELD*) oldField->GenCopy();
newField->SetParent( this );
m_Fields.PushBack( newField );
}
}
......@@ -260,50 +250,28 @@ void LIB_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* dc,
if( convert && drawItem.m_Convert && ( drawItem.m_Convert != convert ) )
continue;
if( !drawFields && drawItem.Type() == COMPONENT_FIELD_DRAW_TYPE )
continue;
if( drawItem.Type() == COMPONENT_PIN_DRAW_TYPE )
{
drawItem.Draw( panel, dc, offset, color, drawMode, &showPinText,
transformMatrix );
drawItem.Draw( panel, dc, offset, color, drawMode,
(void*) &showPinText, transformMatrix );
}
else
else if( drawItem.Type() == COMPONENT_FIELD_DRAW_TYPE )
{
bool force_nofill =
( screen->m_IsPrinting
&& drawItem.m_Fill == FILLED_WITH_BG_BODYCOLOR
&& GetGRForceBlackPenState() );
drawItem.Draw( panel, dc, offset, color, drawMode,
(void*) force_nofill, transformMatrix );
(void*) NULL, transformMatrix );
}
}
if( drawFields )
{
LIB_FIELD* Field;
/*
* The reference designator field is a special case for naming
* convention.
*/
wxString fieldText = m_Prefix.GetFullText( multi );
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 );
for( Field = m_Fields; Field != NULL; Field = Field->Next() )
else
{
if( onlySelected && Field->m_Selected == 0 )
continue;
Field->Draw( panel, dc, offset, color, drawMode, NULL,
transformMatrix );
bool forceNoFill = ( screen->m_IsPrinting
&& drawItem.m_Fill == FILLED_WITH_BG_BODYCOLOR
&& GetGRForceBlackPenState() );
drawItem.Draw( panel, dc, offset, color, drawMode,
(void*) &forceNoFill, transformMatrix );
}
}
/* Enable this to draw the anchor of the component. */
......@@ -351,35 +319,36 @@ void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_ITEM* item,
{
wxASSERT( item != NULL );
/* Value and reference fields cannot be removed. */
if( item->Type() == COMPONENT_FIELD_DRAW_TYPE )
{
LIB_FIELD* field = (LIB_FIELD*)item;
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;
}
}
LIB_DRAW_ITEM_LIST::iterator i;
if( dc != NULL )
item->Draw( panel, dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
DefaultTransformMatrix );
if( item->Type() != COMPONENT_FIELD_DRAW_TYPE )
for( i = m_Drawings.begin(); i < m_Drawings.end(); i++ )
{
for( i = m_Drawings.begin(); i < m_Drawings.end(); i++ )
if( *i == item )
{
if( *i == item )
{
m_Drawings.erase( i );
break;
}
}
}
else
{
LIB_FIELD* field;
for( field = m_Fields; field != NULL; field = field->Next() )
{
if( field == item )
{
m_Fields.Remove( field );
delete field;
break;
}
m_Drawings.erase( i );
break;
}
}
}
......@@ -445,38 +414,35 @@ void LIB_COMPONENT::GetPins( LIB_PIN_LIST& pins, int unit, int convert )
}
/**
* 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.
*/
bool LIB_COMPONENT::Save( FILE* aFile )
{
LIB_FIELD* Field;
size_t i;
LIB_FIELD& value = GetValueField();
/* First line: it s a comment (component name for readers) */
if( fprintf( aFile, "#\n# %s\n#\n", CONV_TO_UTF8( m_Name.m_Text ) ) < 0 )
if( fprintf( aFile, "#\n# %s\n#\n", CONV_TO_UTF8( value.m_Text ) ) < 0 )
return false;
/* Save data */
if( fprintf( aFile, "DEF" ) < 0 )
return false;
if( (m_Name.m_Attributs & TEXT_NO_VISIBLE) == 0 )
if( ( value.m_Attributs & TEXT_NO_VISIBLE ) == 0 )
{
if( fprintf( aFile, " %s", CONV_TO_UTF8( m_Name.m_Text ) ) < 0 )
if( fprintf( aFile, " %s", CONV_TO_UTF8( value.m_Text ) ) < 0 )
return false;
}
else
{
if( fprintf( aFile, " ~%s", CONV_TO_UTF8( m_Name.m_Text ) ) < 0 )
if( fprintf( aFile, " ~%s", CONV_TO_UTF8( value.m_Text ) ) < 0 )
return false;
}
if( !m_Prefix.m_Text.IsEmpty() )
LIB_FIELD& reference = GetReferenceField();
if( !reference.m_Text.IsEmpty() )
{
if( fprintf( aFile, " %s", CONV_TO_UTF8( m_Prefix.m_Text ) ) < 0 )
if( fprintf( aFile, " %s", CONV_TO_UTF8( reference.m_Text ) ) < 0 )
return false;
}
else
......@@ -493,15 +459,18 @@ bool LIB_COMPONENT::Save( FILE* aFile )
m_Options == ENTRY_POWER ? 'P' : 'N' ) < 0 )
return false;
if( !SaveDateAndTime( aFile ) || !m_Prefix.Save( aFile )
|| !m_Name.Save( aFile ) )
if( !SaveDateAndTime( aFile ) )
return false;
for( Field = m_Fields; Field != NULL; Field = Field->Next() )
LIB_FIELD_LIST fields;
GetFields( fields );
for( i = 0; i < fields.size(); i++ )
{
if( Field->m_Text.IsEmpty() && Field->m_Name.IsEmpty() )
if( fields[i].m_Text.IsEmpty() && fields[i].m_Name.IsEmpty() )
continue;
if( !Field->Save( aFile ) )
if( !fields[i].Save( aFile ) )
return false;
}
......@@ -511,9 +480,9 @@ bool LIB_COMPONENT::Save( FILE* aFile )
if( fprintf( aFile, "ALIAS" ) < 0 )
return false;
for( size_t ii = 0; ii < m_AliasList.GetCount(); ii++ )
for( i = 0; i < m_AliasList.GetCount(); i++ )
{
if( fprintf( aFile, " %s", CONV_TO_UTF8( m_AliasList[ii] ) ) < 0 )
if( fprintf( aFile, " %s", CONV_TO_UTF8( m_AliasList[i] ) ) < 0 )
return false;
}
......@@ -527,10 +496,10 @@ bool LIB_COMPONENT::Save( FILE* aFile )
if( fprintf( aFile, "$FPLIST\n" ) < 0 )
return false;
for( size_t ii = 0; ii < m_FootprintList.GetCount(); ii++ )
for( i = 0; i < m_FootprintList.GetCount(); i++ )
{
if( fprintf( aFile, " %s\n",
CONV_TO_UTF8( m_FootprintList[ii] ) ) < 0 )
CONV_TO_UTF8( m_FootprintList[i] ) ) < 0 )
return false;
}
......@@ -550,6 +519,8 @@ bool LIB_COMPONENT::Save( FILE* aFile )
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( item.Type() == COMPONENT_FIELD_DRAW_TYPE )
continue;
if( !item.Save( aFile ) )
return false;
}
......@@ -617,22 +588,30 @@ bool LIB_COMPONENT::Load( FILE* file, char* line, int* lineNum,
m_DrawPinName = (drawname == 'N') ? FALSE : true;
/* Copy part name and prefix. */
LIB_FIELD& value = GetValueField();
strupper( name );
if( name[0] != '~' )
m_Name.m_Text = CONV_FROM_UTF8( name );
{
m_Name = value.m_Text = CONV_FROM_UTF8( name );
}
else
{
m_Name.m_Text = CONV_FROM_UTF8( &name[1] );
m_Name.m_Attributs |= TEXT_NO_VISIBLE;
m_Name = value.m_Text = CONV_FROM_UTF8( &name[1] );
value.m_Attributs |= TEXT_NO_VISIBLE;
}
LIB_FIELD& reference = GetReferenceField();
if( strcmp( prefix, "~" ) == 0 )
{
m_Prefix.m_Text.Empty();
m_Prefix.m_Attributs |= TEXT_NO_VISIBLE;
reference.m_Text.Empty();
reference.m_Attributs |= TEXT_NO_VISIBLE;
}
else
m_Prefix.m_Text = CONV_FROM_UTF8( prefix );
{
reference.m_Text = CONV_FROM_UTF8( prefix );
}
// Copy optional infos
if( ( p = strtok( NULL, " \t\n" ) ) != NULL && *p == 'L' )
......@@ -791,17 +770,18 @@ bool LIB_COMPONENT::LoadField( char* line, wxString& errorMsg )
if( field->m_FieldId == REFERENCE )
{
m_Prefix = *field;
GetReferenceField() = *field;
SAFE_DELETE( field );
}
else if ( field->m_FieldId == VALUE )
{
m_Name = *field;
GetValueField() = *field;
m_Name = field->m_Text;
SAFE_DELETE( field );
}
else
{
m_Fields.PushBack( field );
m_Drawings.push_back( field );
}
return true;
......@@ -852,9 +832,6 @@ EDA_Rect LIB_COMPONENT::GetBoundaryBox( int Unit, int Convert )
bBox.Merge( item.GetBoundingBox() );
}
bBox.Merge( m_Name.GetBoundingBox() );
bBox.Merge( m_Prefix.GetBoundingBox() );
return bBox;
}
......@@ -865,49 +842,80 @@ EDA_Rect LIB_COMPONENT::GetBoundaryBox( int Unit, int Convert )
*/
void LIB_COMPONENT::SetFields( const std::vector <LIB_FIELD> aFields )
{
// Init basic fields (Value = name in lib, and reference):
aFields[VALUE].Copy( &m_Name );
aFields[REFERENCE].Copy( &m_Prefix );
// Remove others fields:
m_Fields.DeleteAll();
LIB_FIELD* field;
for( unsigned ii = FOOTPRINT; ii < aFields.size(); ii++ )
for( size_t i = 0; i < aFields.size(); i++ )
{
bool create = FALSE;
if( !aFields[ii].m_Text.IsEmpty() )
create = true;
if( !aFields[ii].m_Name.IsEmpty()
&& ( aFields[ii].m_Name != ReturnDefaultFieldName( ii ) ) )
create = true;
if( create )
field = GetField( aFields[i].m_FieldId );
if( field )
{
LIB_FIELD*Field = new LIB_FIELD( this, ii );
aFields[ii].Copy( Field );
m_Fields.PushBack( Field );
*field = aFields[i];
if( (int) i == VALUE )
m_Name = field->m_Text;
continue;
}
/* 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] );
m_Drawings.push_back( field );
}
/* for a user field (FieldId >= FIELD1), if a field value is void,
* 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)
*/
for( LIB_FIELD* Field = m_Fields; Field; Field = Field->Next() )
m_Drawings.sort();
}
void LIB_COMPONENT::GetFields( LIB_FIELD_LIST& list )
{
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
Field->SetParent( this );
if( Field->m_FieldId >= FIELD1 )
{
if( Field->m_Text.IsEmpty() )
Field->m_Text = wxT( "~" );
}
else
Field->m_Name.Empty();
if( item.Type() != COMPONENT_FIELD_DRAW_TYPE )
continue;
LIB_FIELD* field = ( LIB_FIELD* ) &item;
list.push_back( *field );
}
}
LIB_FIELD* LIB_COMPONENT::GetField( int id )
{
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( item.Type() != COMPONENT_FIELD_DRAW_TYPE )
continue;
LIB_FIELD* field = ( LIB_FIELD* ) &item;
if( field->m_FieldId == id )
return field;
}
return NULL;
}
LIB_FIELD& LIB_COMPONENT::GetValueField( void )
{
LIB_FIELD* field = GetField( VALUE );
wxASSERT( field != NULL );
return *field;
}
LIB_FIELD& LIB_COMPONENT::GetReferenceField( void )
{
LIB_FIELD* field = GetField( REFERENCE );
wxASSERT( field != NULL );
return *field;
}
/*
* lit date et time de modif composant sous le format:
* "Ti yy/mm/jj hh:mm:ss"
......@@ -959,14 +967,6 @@ bool LIB_COMPONENT::LoadDateAndTime( char* Line )
void LIB_COMPONENT::SetOffset( const wxPoint& offset )
{
m_Name.SetOffset( offset );
m_Prefix.SetOffset( offset );
for( LIB_FIELD* field = m_Fields; field != NULL; field = field->Next() )
{
field->SetOffset( offset );
}
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
item.SetOffset( offset );
......@@ -994,23 +994,15 @@ bool LIB_COMPONENT::HasConversion() const
void LIB_COMPONENT::ClearStatus( void )
{
LIB_FIELD* field;
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
item.m_Flags = 0;
m_Name.m_Flags = 0;
m_Prefix.m_Flags = 0;
for( field = m_Fields.GetFirst(); field != NULL; field = field->Next() )
field->m_Flags = 0;
}
int LIB_COMPONENT::SelectItems( EDA_Rect& rect, int unit, int convert,
bool editPinByPin )
{
int ItemsCount = 0;
int ItemsCount = 0;
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
......@@ -1035,36 +1027,12 @@ int LIB_COMPONENT::SelectItems( EDA_Rect& rect, int unit, int convert,
}
}
if( m_Name.Inside( rect ) )
{
m_Name.m_Selected = IS_SELECTED;
ItemsCount++;
}
if( m_Prefix.Inside( rect ) )
{
m_Prefix.m_Selected = IS_SELECTED;
ItemsCount++;
}
for( LIB_FIELD* field = m_Fields.GetFirst(); field != NULL;
field = field->Next() )
{
if( field->Inside( rect ) )
{
field->m_Selected = IS_SELECTED;
ItemsCount++;
}
}
return ItemsCount;
}
void LIB_COMPONENT::MoveSelectedItems( const wxPoint& offset )
{
LIB_FIELD* field;
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( item.m_Selected == 0 )
......@@ -1074,43 +1042,14 @@ void LIB_COMPONENT::MoveSelectedItems( const wxPoint& offset )
item.m_Flags = item.m_Selected = 0;
}
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;
}
}
m_Drawings.sort();
}
void LIB_COMPONENT::ClearSelectedItems( void )
{
LIB_FIELD* field;
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
item.m_Flags = item.m_Selected = 0;
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;
}
......@@ -1147,8 +1086,6 @@ void LIB_COMPONENT::CopySelectedItems( const wxPoint& offset )
void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& center )
{
LIB_FIELD* field;
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( item.m_Selected == 0 )
......@@ -1158,27 +1095,6 @@ void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& center )
item.m_Flags = item.m_Selected = 0;
}
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;
}
}
m_Drawings.sort();
}
......@@ -1198,8 +1114,6 @@ void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& center )
LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int unit, int convert,
KICAD_T type, const wxPoint& pt )
{
LIB_FIELD* field;
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( ( unit && item.m_Unit && ( unit != item.m_Unit) )
......@@ -1211,20 +1125,6 @@ LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int unit, int convert,
return &item;
}
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;
}
......
......@@ -5,8 +5,6 @@
#ifndef CLASS_LIBENTRY_H
#define CLASS_LIBENTRY_H
#include "dlist.h"
#include "classes_body_items.h"
#include "class_libentry_fields.h"
......@@ -43,7 +41,6 @@ class CMP_LIB_ENTRY : public EDA_BaseStruct
public:
LibrEntryType Type; /* Type = ROOT;
* = ALIAS pour struct LibraryAliasType */
LIB_FIELD m_Name; // name (74LS00 ..) in lib ( = VALUE )
wxString m_Doc; /* documentation for info */
wxString m_KeyWord; /* keyword list (used to select a group of
* components by keyword) */
......@@ -64,7 +61,9 @@ public:
wxString GetLibraryName();
const wxString& GetName() { return m_Name.m_Text; }
virtual const wxString& GetName() const { return m_Name; }
virtual void SetName( const wxString& name ) { m_Name = name; }
/**
* Write the entry document information to a FILE in "*.dcm" format.
......@@ -85,7 +84,10 @@ public:
}
protected:
CMP_LIBRARY* m_lib;
wxString m_Name;
/** Library object that entry is attached to. */
CMP_LIBRARY* m_lib;
};
......@@ -107,7 +109,6 @@ extern int LibraryEntryCompare( const CMP_LIB_ENTRY* LE1,
class LIB_COMPONENT : public CMP_LIB_ENTRY
{
public:
LIB_FIELD m_Prefix; /* Prefix ( U, IC ... ) = REFERENCE */
wxArrayString m_AliasList; /* ALIAS list for the component */
wxArrayString m_FootprintList; /* list of suitable footprint names
* for the component (wildcard names
......@@ -123,7 +124,6 @@ public:
* m_TextInside in mils */
bool m_DrawPinNum;
bool m_DrawPinName;
DLIST<LIB_FIELD> m_Fields; /* Auxiliary Field list (id >= 2 ) */
long m_LastDate; // Last change Date
protected:
......@@ -137,6 +137,12 @@ public:
}
virtual void SetName( const wxString& name )
{
CMP_LIB_ENTRY::SetName( name );
GetValueField().m_Text = name;
}
LIB_COMPONENT( const wxString& name, CMP_LIBRARY* lib = NULL );
LIB_COMPONENT( LIB_COMPONENT& component, CMP_LIBRARY* lib = NULL );
......@@ -181,6 +187,29 @@ public:
*/
void SetFields( const std::vector <LIB_FIELD> aFields );
/**
* Return list of field references of component.
*
* @param list - List to add field references to.
*/
void GetFields( LIB_FIELD_LIST& list );
/**
* Return pointer to the requested field.
*
* @param id - Id of field to return.
*
* @return LIB_FIELD* - Pointer to field if found. NULL is returned if
* field not found.
*/
LIB_FIELD* GetField( int id );
/** Return reference to the value field. */
LIB_FIELD& GetValueField( void );
/** Return reference to the reference designator field. */
LIB_FIELD& GetReferenceField( void );
/**
* Draw component.
*
......
......@@ -56,6 +56,7 @@ LIB_FIELD::LIB_FIELD( int idfield ) :
LIB_FIELD::LIB_FIELD( const LIB_FIELD& field ) : LIB_DRAW_ITEM( field )
{
m_FieldId = field.m_FieldId;
m_Pos = field.m_Pos;
m_Size = field.m_Size;
m_Width = field.m_Width;
......@@ -431,7 +432,7 @@ int LIB_FIELD::DoCompare( const LIB_DRAW_ITEM& other ) const
const LIB_FIELD* tmp = ( LIB_FIELD* ) &other;
if( m_FieldId == tmp->m_FieldId )
if( m_FieldId != tmp->m_FieldId )
return m_FieldId - tmp->m_FieldId;
int result = m_Text.CmpNoCase( tmp->m_Text );
......
......@@ -9,6 +9,12 @@
#include "classes_body_items.h"
class LIB_FIELD;
typedef std::vector< LIB_FIELD > LIB_FIELD_LIST;
/* Fields , same as component fields.
* can be defined in libraries (mandatory for ref and value, ca be useful for
* footprints)
......
......@@ -29,7 +29,7 @@ loading components into a schematic." );
static bool DuplicateEntryName( const CMP_LIB_ENTRY& item1,
const CMP_LIB_ENTRY& item2 )
{
return item1.m_Name.m_Text.CmpNoCase( item2.m_Name.m_Text ) == 0;
return item1.GetName().CmpNoCase( item2.GetName() ) == 0;
}
......@@ -100,9 +100,15 @@ void CMP_LIBRARY::GetEntryNames( wxArrayString& names, bool sort,
BOOST_FOREACH( CMP_LIB_ENTRY& entry, m_Entries )
{
if( makeUpperCase )
names.Add( entry.m_Name.m_Text.MakeUpper() );
{
wxString tmp = entry.GetName();
tmp.MakeUpper();
names.Add( tmp );
}
else
{
names.Add( entry.GetName() );
}
}
if( sort )
......@@ -346,7 +352,7 @@ library <%s>" ),
RemoveEntry( AliasName );
/* Change the root name. */
Root->m_Name.m_Text = AliasName;
Root->SetName( AliasName );
}
......
......@@ -63,6 +63,9 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_COMPONENT& libComponent, DrawSheetPath* sheet,
bool setNewItemFlag ) :
SCH_ITEM( NULL, TYPE_SCH_COMPONENT )
{
size_t i;
LIB_FIELD_LIST libFields;
Init( pos );
m_Multi = unit;
......@@ -73,55 +76,49 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_COMPONENT& libComponent, DrawSheetPath* sheet,
if( setNewItemFlag )
m_Flags = IS_NEW | IS_MOVED;
GetField( VALUE )->m_Pos = libComponent.m_Name.m_Pos + m_Pos;
GetField( VALUE )->ImportValues( libComponent.m_Name );
GetField( VALUE )->m_Text = m_ChipName;
wxString msg = libComponent.m_Prefix.m_Text;
if( msg.IsEmpty() )
msg = wxT( "U" );
msg += wxT( "?" );
// update the reference -- just the prefix for now.
SetRef( sheet, msg );
GetField( REFERENCE )->m_Pos = libComponent.m_Prefix.m_Pos + m_Pos;
GetField( REFERENCE )->ImportValues( libComponent.m_Prefix );
m_PrefixString = libComponent.m_Prefix.m_Text;
/* Init des autres champs si predefinis dans la librairie */
LIB_FIELD* EntryField;
int ii;
libComponent.GetFields( libFields );
for( EntryField = libComponent.m_Fields; EntryField != NULL;
EntryField = EntryField->Next() )
for( i = 0; i < libFields.size(); i++ )
{
if( EntryField->m_Text.IsEmpty() && EntryField->m_Name.IsEmpty() )
if( libFields[i].m_Text.IsEmpty() && libFields[i].m_Name.IsEmpty() )
continue;
ii = EntryField->m_FieldId;
if( ii < 2 ) // Reference or value, already done
continue;
if( ii >= GetFieldCount() )
{ // This entry has more than the default count: add extra fields
while( ii >= GetFieldCount() )
/* Add extra fields if library component has more than the default
* number of fields.
*/
if( (int) i >= GetFieldCount() )
{
while( (int) i >= GetFieldCount() )
{
int field_id = GetFieldCount();
SCH_CMP_FIELD field( wxPoint( 0, 0 ), field_id, this,
ReturnDefaultFieldName( ii ) );
SCH_CMP_FIELD field( wxPoint( 0, 0 ), GetFieldCount(), this,
ReturnDefaultFieldName( i ) );
AddField( field );
}
}
SCH_CMP_FIELD* curr_field = GetField( ii );
SCH_CMP_FIELD* schField = GetField( i );
curr_field->m_Pos = m_Pos + EntryField->m_Pos;
curr_field->ImportValues( *EntryField );
curr_field->m_Text = EntryField->m_Text;
curr_field->m_Name =
( ii < FIELD1 ) ? ReturnDefaultFieldName( ii ) : EntryField->m_Name;
schField->m_Pos = m_Pos + libFields[i].m_Pos;
schField->ImportValues( libFields[i] );
schField->m_Text = libFields[i].m_Text;
schField->m_Name = ( i < FIELD1 ) ? ReturnDefaultFieldName( i ) :
libFields[i].m_Name;
}
wxString msg = libComponent.GetReferenceField().m_Text;
if( msg.IsEmpty() )
msg = wxT( "U" );
msg += wxT( "?" );
// update the reference -- just the prefix for now.
SetRef( sheet, msg );
/* Use the schematic component name instead of the library value field
* name.
*/
GetField( VALUE )->m_Text = m_ChipName;
}
......
......@@ -108,7 +108,7 @@ void WinEDA_CreateCmpDialog::SetComponentData( LIB_COMPONENT & component )
parent->SetShowDeMorgan( m_AsConvert->GetValue() );
component.SetPartCount( m_PartsCount->GetSelection() + 1 );
component.m_Prefix.m_Text = m_Reference->GetValue();
component.GetReference().m_Text = m_Reference->GetValue();
if ( m_PinNameInside->GetValue() == FALSE)
component.m_TextInside = 0;
else
......
......@@ -720,11 +720,13 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
RedrawOneStruct( m_Parent->DrawPanel, &dc, m_Cmp, g_XorMode );
/* Initialise fields values to default values found in library: */
m_Cmp->GetField( REFERENCE )->m_Pos = entry->m_Prefix.m_Pos + m_Cmp->m_Pos;
m_Cmp->GetField( REFERENCE )->ImportValues( entry->m_Prefix );
LIB_FIELD& refField = entry->GetReferenceField();
m_Cmp->GetField( REFERENCE )->m_Pos = refField.m_Pos + m_Cmp->m_Pos;
m_Cmp->GetField( REFERENCE )->ImportValues( refField );
m_Cmp->GetField( VALUE )->m_Pos = entry->m_Name.m_Pos + m_Cmp->m_Pos;
m_Cmp->GetField( VALUE )->ImportValues( entry->m_Name );
LIB_FIELD& valField = entry->GetValueField();
m_Cmp->GetField( VALUE )->m_Pos = valField.m_Pos + m_Cmp->m_Pos;
m_Cmp->GetField( VALUE )->ImportValues( valField );
m_Cmp->SetRotationMiroir( CMP_NORMAL );
......
......@@ -416,15 +416,16 @@ static bool SortFieldsById(const LIB_FIELD& item1, const LIB_FIELD& item2)
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::InitBuffers( void )
/***********************************************************/
{
LIB_FIELD_LIST fields;
m_LibEntry->GetFields( fields );
// copy all the fields to a work area
m_FieldsBuf.reserve(NUMBER_OF_FIELDS);
m_FieldsBuf.push_back( m_LibEntry->m_Prefix );
m_FieldsBuf.push_back( m_LibEntry->m_Name );
// Creates a working copy of fields
for( LIB_FIELD* field = m_LibEntry->m_Fields; field != NULL; field = field->Next() )
m_FieldsBuf.push_back( *field );
for( size_t i = 0; i < fields.size(); i++ )
m_FieldsBuf.push_back( fields[i] );
// Display 12 fields (or more), and add missing fields
LIB_FIELD blank( 2 );
......
......@@ -33,7 +33,7 @@
<property name="name">DIALOG_LIB_EDIT_DRAW_ITEM_BASE</property>
<property name="pos"></property>
<property name="size"></property>
<property name="style">wxDEFAULT_DIALOG_STYLE</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass"></property>
<property name="title">Drawing Properties</property>
<property name="tooltip"></property>
......
......@@ -55,7 +55,7 @@ class DIALOG_LIB_EDIT_DRAW_ITEM_BASE : public wxDialog
wxButton* m_sdbSizer1Cancel;
public:
DIALOG_LIB_EDIT_DRAW_ITEM_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Drawing Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE );
DIALOG_LIB_EDIT_DRAW_ITEM_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Drawing Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_LIB_EDIT_DRAW_ITEM_BASE();
};
......
......@@ -527,7 +527,7 @@ lost!\n\nClear the current component from the screen?" ) ) )
}
LIB_COMPONENT* component = new LIB_COMPONENT( name );
component->m_Prefix.m_Text = dlg.GetReference();
component->GetReferenceField().m_Text = dlg.GetReference();
component->SetPartCount( dlg.GetPartCount() );
// Initialize component->m_TextInside member:
// if 0, pin text is outside the body (on the pin)
......
......@@ -160,6 +160,8 @@ void WinEDA_LibeditFrame::EditField( wxDC* DC, LIB_FIELD* Field )
Get_Message( title, _( "Edit field" ), Text, this );
Text.Replace( wxT( " " ), wxT( "_" ) );
wxString fieldText = Field->GetFullText( m_unit );
/* If the value field is changed, this is equivalent to creating a new
* component from the old one. Check for an existing library entry of
* this "new" component and change the value only if there is no existing
......@@ -194,9 +196,9 @@ not conflict with any library entries." ),
DisplayError( this, msg );
return;
}
}
wxString fieldText = Field->GetFullText( m_unit );
Field->GetParent()->SetName( Text );
}
Field->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, &fieldText,
DefaultTransformMatrix );
......
......@@ -101,6 +101,8 @@ void WinEDA_LibeditFrame::LoadOneSymbol( void )
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawList )
{
if( item.Type() == COMPONENT_FIELD_DRAW_TYPE )
continue;
if( item.m_Unit )
item.m_Unit = m_unit;
if( item.m_Convert )
......@@ -146,7 +148,7 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
wxString default_path = wxGetApp().ReturnLastVisitedLibraryPath();
wxFileDialog dlg( this, _( "Export Symbol Drawings" ), default_path,
m_component->m_Name.m_Text, SymbolFileWildcard,
m_component->GetName(), SymbolFileWildcard,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_CANCEL )
......@@ -182,14 +184,14 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
/* Creation du commentaire donnant le nom du composant */
fprintf( ExportFile, "# SYMBOL %s\n#\n",
CONV_TO_UTF8( m_component->m_Name.m_Text ) );
CONV_TO_UTF8( m_component->GetName() ) );
/* Generation des lignes utiles */
fprintf( ExportFile, "DEF %s",
CONV_TO_UTF8( m_component->m_Name.m_Text ) );
if( !m_component->m_Prefix.m_Text.IsEmpty() )
CONV_TO_UTF8( m_component->GetName() ) );
if( !m_component->GetReferenceField().m_Text.IsEmpty() )
fprintf( ExportFile, " %s",
CONV_TO_UTF8( m_component->m_Prefix.m_Text ) );
CONV_TO_UTF8( m_component->GetReferenceField().m_Text ) );
else
fprintf( ExportFile, " ~" );
......@@ -201,8 +203,8 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
1, 0 /* unused */, 'N' );
/* Position / orientation / visibilite des champs */
m_component->m_Prefix.Save( ExportFile );
m_component->m_Name.Save( ExportFile );
m_component->GetReferenceField().Save( ExportFile );
m_component->GetValueField().Save( ExportFile );
LIB_DRAW_ITEM_LIST& drawList = m_component->GetDrawItemList();
......@@ -210,7 +212,9 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawList )
{
/* Elimination des elements non relatifs a l'unite */
if( item.Type() == COMPONENT_FIELD_DRAW_TYPE )
continue;
/* Don't save unused parts or alternate body styles. */
if( m_unit && item.m_Unit && ( item.m_Unit != m_unit ) )
continue;
if( m_convert && item.m_Convert && ( item.m_Convert != m_convert ) )
......
......@@ -216,7 +216,7 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( CMP_LIBRARY* Lib, int Flag )
LibEntry = Lib->GetNextEntry( m_entryName );
if( LibEntry )
CmpName = LibEntry->m_Name.m_Text;
CmpName = LibEntry->GetName();
}
if( Flag == PREVIOUS_PART )
......@@ -224,7 +224,7 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( CMP_LIBRARY* Lib, int Flag )
LibEntry = Lib->GetPreviousEntry( m_entryName );
if( LibEntry )
CmpName = LibEntry->m_Name.m_Text;
CmpName = LibEntry->GetName();
}
m_unit = 1;
......@@ -291,12 +291,12 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
/* Temporarily change the name field text to reflect the alias name. */
tmp = component->GetName();
component->m_Name.m_Text = alias->GetName();
component->SetName( alias->GetName() );
if( m_unit < 1 )
m_unit = 1;
if( m_convert < 1 )
m_convert = 1;
component->m_Name.m_Text = tmp;
component->SetName( tmp );
}
else
{
......@@ -308,7 +308,7 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
GR_DEFAULT_DRAWMODE );
if( !tmp.IsEmpty() )
component->m_Name.m_Text = tmp;
component->SetName( tmp );
ClearMsgPanel();
AppendMsgPanel( _( "Part" ), component->GetName(), BLUE, 6 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment