Commit d8fae88f authored by charras's avatar charras

Eeschema, libedit: fixed last problems when editing alias info.

Now alias changes can be undone, and are correctly updated in lib
parent 124074c6
...@@ -4,6 +4,16 @@ KiCad ChangeLog 2010 ...@@ -4,6 +4,16 @@ KiCad ChangeLog 2010
Please add newer entries at the top, list the date and your name with Please add newer entries at the top, list the date and your name with
email address. email address.
2010-Feb-17 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================
Eeschema, libedit: fixed last problems when editing alias info.
Now alias changes can be undone, and are correctly updated in lib
when updating the current edited component in memory
New code could be a good starting point to store all aliases info in the
root component,
and also easily store it to the *.lib files and remove the .dcm associated files
(most of code is done)
2010-Feb-14 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr> 2010-Feb-14 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================ ================================================================================
......
...@@ -126,7 +126,7 @@ int LibraryEntryCompare( const CMP_LIB_ENTRY* aItem1, const CMP_LIB_ENTRY* aItem ...@@ -126,7 +126,7 @@ int LibraryEntryCompare( const CMP_LIB_ENTRY* aItem1, const CMP_LIB_ENTRY* aItem
/* Class to define an alias of a component /* Class to define an alias of a component
* An alias uses the component definition (graphic, pins...) * An alias uses the component definition (graphic, pins...)
* but has its own name and documentation. * but has its own name, keywords and documentation.
* Therefore, when the component is modified, alias of this component are * Therefore, when the component is modified, alias of this component are
* modified. * modified.
* This is a simple method to create components with differs very few * This is a simple method to create components with differs very few
...@@ -140,6 +140,8 @@ LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent, ...@@ -140,6 +140,8 @@ LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent,
wxASSERT( aRootComponent != NULL && aRootComponent->isComponent() ); wxASSERT( aRootComponent != NULL && aRootComponent->isComponent() );
root = aRootComponent; root = aRootComponent;
if( aLibrary == NULL )
library = aRootComponent->GetLibrary();
} }
...@@ -201,6 +203,7 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary ) ...@@ -201,6 +203,7 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary )
LIB_DRAW_ITEM* newItem; LIB_DRAW_ITEM* newItem;
m_AliasList = aComponent.m_AliasList; m_AliasList = aComponent.m_AliasList;
m_aliasListData = aComponent.m_aliasListData;
m_FootprintList = aComponent.m_FootprintList; m_FootprintList = aComponent.m_FootprintList;
unitCount = aComponent.unitCount; unitCount = aComponent.unitCount;
m_UnitSelectionLocked = aComponent.m_UnitSelectionLocked; m_UnitSelectionLocked = aComponent.m_UnitSelectionLocked;
...@@ -1304,3 +1307,143 @@ void LIB_COMPONENT::SetConversion( bool aSetConvert ) ...@@ -1304,3 +1307,143 @@ void LIB_COMPONENT::SetConversion( bool aSetConvert )
} }
} }
} }
/* accessors to aliases data, used by the component editor, during edition
*/
/** Function LocateAliasData
* @return an index in array string to the alias data (doc, keywords, docfile)
* or -1 if not found
* @param aAliasName = the alias name
* @param aCreateIfNotExist = true if the alias data must be created, when not exists
*/
int LIB_COMPONENT::LocateAliasData( const wxString & aAliasName, bool aCreateIfNotExist)
{
int idx = -1;
for( unsigned ii = 0; ii < m_aliasListData.size(); ii += ALIAS_NEXT_IDX )
{
if( aAliasName.CmpNoCase( m_aliasListData[ii] ) != 0 )
continue;
// Found!
idx = (int) ii;
break;
}
// Alias not found, create on demand
if( aCreateIfNotExist && (idx < 0) )
{
idx = (int) m_aliasListData.size();
m_aliasListData.Add(aAliasName);
// Add void strinds for data:
m_aliasListData.Add(wxEmptyString); //Doc string
m_aliasListData.Add(wxEmptyString); //keywords string
m_aliasListData.Add(wxEmptyString); //Doc fliname string
}
return idx;
}
/** Function GetAliasDataDoc
* @param aAliasName = the alias name
* @return the Doc string
*/
wxString LIB_COMPONENT::GetAliasDataDoc( const wxString & aAliasName )
{
wxString data;
int idx = LocateAliasData( aAliasName);
if ( idx >= 0 )
data = m_aliasListData[idx + ALIAS_DOC_IDX];
return data;
}
/** Function GetAliasDataKeyWords
* @param aAliasName = the alias name
* @return aAliasData = the keywords string
*/
wxString LIB_COMPONENT::GetAliasDataKeyWords( const wxString & aAliasName )
{
wxString data;
int idx = LocateAliasData( aAliasName);
if ( idx >= 0 )
data = m_aliasListData[idx + ALIAS_KEYWORD_IDX];
return data;
}
/** Function GetAliasDataDocFileName
* @param aAliasName = the alias name
* @return the Doc filename string
*/
wxString LIB_COMPONENT::GetAliasDataDocFileName( const wxString & aAliasName )
{
wxString data;
int idx = LocateAliasData( aAliasName);
if ( idx >= 0 )
data = m_aliasListData[idx + ALIAS_DOC_FILENAME_IDX];
return data;
}
/** Function SetAliasDataDoc
* @param aAliasName = the alias name
* @param aAliasData = the Doc string
*/
void LIB_COMPONENT::SetAliasDataDoc( const wxString & aAliasName, const wxString & aAliasData )
{
int idx = LocateAliasData( aAliasName, true);
m_aliasListData[idx + ALIAS_DOC_IDX] = aAliasData;
}
/** Function SetAliasDataKeywords
* @param aAliasName = the alias name
* @param aAliasData = the keywords string
*/
void LIB_COMPONENT::SetAliasDataKeywords( const wxString & aAliasName, const wxString & aAliasData )
{
int idx = LocateAliasData( aAliasName, true);
m_aliasListData[idx + ALIAS_KEYWORD_IDX] = aAliasData;
}
/** Function SetAliasDataDocFileName
* @param aAliasName = the alias name
* @param aAliasData = the Doc filename string
*/
void LIB_COMPONENT::SetAliasDataDocFileName( const wxString & aAliasName, const wxString & aAliasData )
{
int idx = LocateAliasData( aAliasName, true);
m_aliasListData[idx + ALIAS_DOC_FILENAME_IDX] = aAliasData;
}
/** Function RemoveAliasData
* remove an alias data from list
* @param aAliasName = the alias name
*/
void LIB_COMPONENT::RemoveAliasData(const wxString & aAliasName )
{
int idx = LocateAliasData( aAliasName);
if ( idx >= 0 )
m_aliasListData.RemoveAt(idx + ALIAS_NAME_IDX, ALIAS_NEXT_IDX);
}
/** Function CollectAliasesData
* store in m_aliasListData alias data (doc, keywords, docfile)
* for each alias found in m_AliasList
*/
void LIB_COMPONENT::CollectAliasesData( CMP_LIBRARY* aLibrary )
{
for( unsigned ii = 0; ii < m_AliasList.GetCount(); ii++ )
{
CMP_LIB_ENTRY* entry = aLibrary->FindEntry( m_AliasList[ii] );
if ( ! entry ) continue;
SetAliasDataDoc( m_AliasList[ii], entry->GetDescription() );
SetAliasDataKeywords( m_AliasList[ii], entry->GetKeyWords() );
SetAliasDataDocFileName( m_AliasList[ii], entry->GetDocFileName() );
}
}
...@@ -23,7 +23,7 @@ enum LibrEntryType ...@@ -23,7 +23,7 @@ enum LibrEntryType
ALIAS /* This is an alias of a true component */ ALIAS /* This is an alias of a true component */
}; };
/* values for member .m_Options */ /* values for member .m_options */
enum LibrEntryOptions enum LibrEntryOptions
{ {
ENTRY_NORMAL, // Libentry is a standard component (real or alias) ENTRY_NORMAL, // Libentry is a standard component (real or alias)
...@@ -67,6 +67,8 @@ public: ...@@ -67,6 +67,8 @@ public:
wxString GetLibraryName(); wxString GetLibraryName();
CMP_LIBRARY* GetLibrary() {return library;}
virtual const wxString& GetName() const { return name; } virtual const wxString& GetName() const { return name; }
virtual void SetName( const wxString& aName ) { name = aName; } virtual void SetName( const wxString& aName ) { name = aName; }
...@@ -159,6 +161,34 @@ protected: ...@@ -159,6 +161,34 @@ protected:
LIB_DRAW_ITEM_LIST drawings; /* How to draw this part */ LIB_DRAW_ITEM_LIST drawings; /* How to draw this part */
public: public:
/* Offsets used in editing library component,
* for handle aliases data in m_AliasListData array string
* when editing a library component, aliases data is stored
* in m_AliasListData.
* 4 strings by alias are stored:
* name, doc, keywords and doc filename
* these constants are indexes in m_AliasListData
* to read/write strings for a given alias
*/
enum alias_idx
{
ALIAS_NAME_IDX = 0,
ALIAS_DOC_IDX = 1,
ALIAS_KEYWORD_IDX = 2,
ALIAS_DOC_FILENAME_IDX = 3,
ALIAS_NEXT_IDX = 4
};
private:
wxArrayString m_aliasListData; /* ALIAS data (name, doc, keywords and doc filename).
* Used only by the component editor LibEdit
* to store aliases info during edition
* usually void outside the component editor */
public:
LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary = NULL );
LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary = NULL );
~LIB_COMPONENT();
virtual wxString GetClass() const virtual wxString GetClass() const
{ {
return wxT( "LIB_COMPONENT" ); return wxT( "LIB_COMPONENT" );
...@@ -171,10 +201,68 @@ public: ...@@ -171,10 +201,68 @@ public:
GetValueField().m_Text = aName; GetValueField().m_Text = aName;
} }
LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary = NULL ); /* accessors to aliases data, used by the component editor, during edition
LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary = NULL ); */
/** Function CollectAliasesData
* store in m_aliasListData alias data (doc, keywords, docfile)
* for each alias found in m_AliasList
*/
void CollectAliasesData( CMP_LIBRARY* aLibrary );
~LIB_COMPONENT(); /** Function LocateAliasData
* @return an index in array string to the alias data (doc, keywords, docfile)
* or -1 if not found
* @param aAliasName = the alias name
* @param aCreateIfNotExist = true if the alias data must be created, when not exists
*/
int LocateAliasData( const wxString & aAliasName, bool aCreateIfNotExist = false);
/** Function GetAliasDataDoc
* @param aAliasName = the alias name
* @return the Doc string
*/
wxString GetAliasDataDoc( const wxString & aAliasName );
/** Function GetAliasDataKeyWords
* @param aAliasName = the alias name
* @return aAliasData = the keywords string
*/
wxString GetAliasDataKeyWords( const wxString & aAliasName );
/** Function GetAliasDataDocFileName
* @param aAliasName = the alias name
* @return the Doc filename string
*/
wxString GetAliasDataDocFileName( const wxString & aAliasName );
/** Function SetAliasDataDoc
* @param aAliasName = the alias name
* @return aAliasData = the Doc string
*/
void SetAliasDataDoc( const wxString & aAliasName, const wxString & aAliasData );
/** Function SetAliasDataKeywords
* @param aAliasName = the alias name
* @param aAliasData = the keywords string
*/
void SetAliasDataKeywords( const wxString & aAliasName, const wxString & aAliasData );
/** Function SetAliasDataDocFileName
* @param aAliasName = the alias name
* @param aAliasData = the Doc filename string
*/
void SetAliasDataDocFileName( const wxString & aAliasName, const wxString & aAliasData );
/** Function ClearAliasDataDoc
* clear aliases data list
*/
void ClearAliasDataDoc( ) { m_aliasListData.Clear(); }
/** Function RemoveAliasData
* remove an alias data from list
* @param aAliasName = the alias name
*/
void RemoveAliasData(const wxString & aAliasName );
EDA_Rect GetBoundaryBox( int aUnit, int aConvert ); EDA_Rect GetBoundaryBox( int aUnit, int aConvert );
......
...@@ -232,6 +232,7 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent ) ...@@ -232,6 +232,7 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent )
wxASSERT( aComponent != NULL ); wxASSERT( aComponent != NULL );
LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aComponent, this ); LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aComponent, this );
newCmp->ClearAliasDataDoc(); // Remove data used only in edition
if( newCmp == NULL ) if( newCmp == NULL )
return NULL; return NULL;
...@@ -283,20 +284,25 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent ) ...@@ -283,20 +284,25 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent )
for( size_t i = 0; i < newCmp->m_AliasList.GetCount(); i++ ) for( size_t i = 0; i < newCmp->m_AliasList.GetCount(); i++ )
{ {
LIB_ALIAS* alias = FindAlias( newCmp->m_AliasList[ i ] ); wxString aliasname = newCmp->m_AliasList[ i ];
LIB_ALIAS* alias = FindAlias( aliasname );
if( alias == NULL ) if( alias == NULL )
{ {
alias = new LIB_ALIAS( newCmp->m_AliasList[ i ], newCmp ); alias = new LIB_ALIAS( aliasname, newCmp );
entries.push_back( alias ); entries.push_back( alias );
} }
else if( alias->GetComponent()->GetName().CmpNoCase( newCmp->GetName() ) != 0 ) else if( alias->GetComponent()->GetName().CmpNoCase( newCmp->GetName() ) != 0 )
{ {
// Remove alias from library and alias list of its root component // Remove alias from library and alias list of its root component
RemoveEntry( alias ); RemoveEntry( alias );
alias = new LIB_ALIAS( newCmp->m_AliasList[ i ], newCmp ); alias = new LIB_ALIAS( aliasname, newCmp );
entries.push_back( alias ); entries.push_back( alias );
} }
// Update alias data:
alias->SetDescription( aComponent->GetAliasDataDoc( aliasname ) );
alias->SetKeyWords( aComponent->GetAliasDataKeyWords( aliasname ) );
alias->SetDocFileName( aComponent->GetAliasDataDocFileName( aliasname ) );
} }
entries.push_back( (CMP_LIB_ENTRY*) newCmp ); entries.push_back( (CMP_LIB_ENTRY*) newCmp );
...@@ -442,29 +448,26 @@ LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* aOldComponent, ...@@ -442,29 +448,26 @@ LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* aOldComponent,
size_t i; size_t i;
LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aNewComponent, this ); LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aNewComponent, this );
newCmp->ClearAliasDataDoc( ); // this data is currently used only when editing the component
/* We want to remove the old root component, so we must remove old aliases. /* We want to remove the old root component, so we must remove old aliases.
* even if they are not modified, because their root component will be removed * even if they are not modified, because their root component will be removed
*/ */
for( i = 0; i < aOldComponent->m_AliasList.GetCount(); i++ ) for( i = 0; i < aOldComponent->m_AliasList.GetCount(); i++ )
{ {
/* wxLogDebug( wxT( "Removing alias <%s> from component <%s> in library <%s>." ),
GetChars( aOldComponent->m_AliasList[ i ] ),
GetChars( aOldComponent->GetName() ),
GetChars( fileName.GetName() ) );
*/
RemoveEntryName( aOldComponent->m_AliasList[ i ] ); RemoveEntryName( aOldComponent->m_AliasList[ i ] );
} }
/* Now, add current aliases. */ /* Now, add current aliases. */
for( i = 0; i < aNewComponent->m_AliasList.GetCount(); i++ ) for( i = 0; i < aNewComponent->m_AliasList.GetCount(); i++ )
{ {
/* wxLogDebug( wxT( "Adding alias <%s> from component <%s> in library <%s>." ), wxString aliasname = aNewComponent->m_AliasList[ i ];
GetChars( aNewComponent->m_AliasList[ i ] ), LIB_ALIAS* alias = new LIB_ALIAS( aliasname, newCmp );
GetChars( aNewComponent->GetName() ), // Update alias data:
GetChars( fileName.GetName() ) ); alias->SetDescription( aNewComponent->GetAliasDataDoc( aliasname ) );
*/ alias->SetKeyWords( aNewComponent->GetAliasDataKeyWords( aliasname ) );
LIB_ALIAS* alias = new LIB_ALIAS( aNewComponent->m_AliasList[ i ], newCmp ); alias->SetDocFileName( aNewComponent->GetAliasDataDocFileName( aliasname ) );
// Add it in library
entries.push_back( alias ); entries.push_back( alias );
} }
...@@ -589,7 +592,7 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg ) ...@@ -589,7 +592,7 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
|| !vers.GetNextToken().ToLong( & minor ) || minor < 0L || !vers.GetNextToken().ToLong( & minor ) || minor < 0L
|| minor > 99 ) || minor > 99 )
{ {
#if 0 // Note for defeloppers: #if 0 // Note for developers:
// Not sure this warning is very useful: old designs *must* be always loadable // Not sure this warning is very useful: old designs *must* be always loadable
wxLogWarning( wxT( "The component library <%s> header version \ wxLogWarning( wxT( "The component library <%s> header version \
number is invalid.\n\nIn future versions of EESchema this library may not \ number is invalid.\n\nIn future versions of EESchema this library may not \
......
...@@ -1097,9 +1097,12 @@ EDA_Rect SCH_COMPONENT::GetBoundingBox() ...@@ -1097,9 +1097,12 @@ EDA_Rect SCH_COMPONENT::GetBoundingBox()
void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame ) void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame )
{ {
LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName ); // search for the component in lib
// Entry and root_component can differ if Entry is an alias
CMP_LIB_ENTRY* Entry = CMP_LIBRARY::FindLibraryEntry( m_ChipName );
LIB_COMPONENT* root_component = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
if( Entry == NULL ) if( (Entry == NULL) || (root_component == NULL) )
return; return;
wxString msg; wxString msg;
...@@ -1110,17 +1113,19 @@ void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame ) ...@@ -1110,17 +1113,19 @@ void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame )
GetRef(((WinEDA_SchematicFrame*)frame)->GetSheet()), GetRef(((WinEDA_SchematicFrame*)frame)->GetSheet()),
DARKCYAN ); DARKCYAN );
if( Entry->isPower() ) if( root_component->isPower() )
msg = _( "Power symbol" ); msg = _( "Power symbol" );
else else
msg = _( "Name" ); msg = _( "Name" );
frame->AppendMsgPanel( msg, GetField( VALUE )->m_Text, DARKCYAN ); frame->AppendMsgPanel( msg, GetField( VALUE )->m_Text, DARKCYAN );
frame->AppendMsgPanel( _( "Component" ), m_ChipName, BROWN );
msg = Entry->GetLibraryName(); // Display component reference in library and library
frame->AppendMsgPanel( _( "Component" ), m_ChipName, BROWN );
if( Entry->isAlias( ) )
frame->AppendMsgPanel( _( "Alias of" ), root_component->GetName(), BROWN );
frame->AppendMsgPanel( _( "Library" ), Entry->GetLibraryName(), BROWN );
frame->AppendMsgPanel( _( "Library" ), msg, DARKRED ); // Display description of the component, and keywords found in lib
frame->AppendMsgPanel( _( "Description" ), Entry->GetDescription(), DARKCYAN ); frame->AppendMsgPanel( _( "Description" ), Entry->GetDescription(), DARKCYAN );
frame->AppendMsgPanel( _( "Key words" ), Entry->GetKeyWords(), DARKCYAN ); frame->AppendMsgPanel( _( "Key words" ), Entry->GetKeyWords(), DARKCYAN );
} }
......
...@@ -102,29 +102,24 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnCancelClick( wxCommandEvent& event ) ...@@ -102,29 +102,24 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnCancelClick( wxCommandEvent& event )
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitPanelDoc() void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitPanelDoc()
{ {
CMP_LIB_ENTRY* entry;
LIB_COMPONENT* component = m_Parent->GetComponent(); LIB_COMPONENT* component = m_Parent->GetComponent();
CMP_LIBRARY* library = m_Parent->GetLibrary();
if( component == NULL ) if( component == NULL )
return; return;
if( m_Parent->GetAliasName().IsEmpty() ) wxString aliasname = m_Parent->GetAliasName();
if( aliasname.IsEmpty() ) // The root component is selected
{ {
entry = component; m_DocCtrl->SetValue( component->GetDescription() );
m_KeywordsCtrl->SetValue( component->GetKeyWords() );
m_DocfileCtrl->SetValue( component->GetDocFileName() );
} }
else else // An alias is currently selected
{ {
entry = m_DocCtrl->SetValue( component->GetAliasDataDoc( aliasname ) );
( CMP_LIB_ENTRY* ) library->FindAlias( m_Parent->GetAliasName() ); m_KeywordsCtrl->SetValue( component->GetAliasDataKeyWords( aliasname ) );
m_DocfileCtrl->SetValue( component->GetAliasDataDocFileName( aliasname ) );
if( entry == NULL )
return;
} }
m_DocCtrl->SetValue( entry->GetDescription() );
m_KeywordsCtrl->SetValue( entry->GetKeyWords() );
m_DocfileCtrl->SetValue( entry->GetDocFileName() );
} }
......
...@@ -58,7 +58,6 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event ) ...@@ -58,7 +58,6 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event )
/* Update the doc, keyword and doc filename strings */ /* Update the doc, keyword and doc filename strings */
size_t i; size_t i;
int index; int index;
CMP_LIB_ENTRY* entry = NULL;
LIB_COMPONENT* component = m_Parent->GetComponent(); LIB_COMPONENT* component = m_Parent->GetComponent();
if( component == NULL ) if( component == NULL )
{ {
...@@ -68,33 +67,20 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event ) ...@@ -68,33 +67,20 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event )
m_Parent->SaveCopyInUndoList( component ); m_Parent->SaveCopyInUndoList( component );
CMP_LIBRARY* library = m_Parent->GetLibrary(); wxString aliasname = m_Parent->GetAliasName();
if( m_Parent->GetAliasName().IsEmpty() ) if( aliasname.IsEmpty() ) // The root component is selected
{
entry = (CMP_LIB_ENTRY*) component;
}
else if ( library )
{ {
entry = library->FindEntry( m_Parent->GetAliasName() ); component->SetDescription( m_DocCtrl->GetValue() );
component->SetKeyWords( m_KeywordsCtrl->GetValue() );
component->SetDocFileName( m_DocfileCtrl->GetValue() );
} }
if( entry == NULL ) else // An alias is selected: update keyworks (if thias alias is new, it will be added in aliacd data list)
{ {
wxString msg; component->SetAliasDataDoc(aliasname, m_DocCtrl->GetValue() );
msg.Printf( _( "Alias <%s> not found for component <%s> in library \ component->SetAliasDataKeywords(aliasname, m_KeywordsCtrl->GetValue() );
<%s>." ), component->SetAliasDataDocFileName(aliasname, m_DocfileCtrl->GetValue() );
GetChars( m_Parent->GetAliasName() ),
GetChars( component->GetName() ),
GetChars( library->GetName() ) );
wxMessageBox( msg, _( "Component Library Error" ),
wxID_OK | wxICON_ERROR, this );
}
else
{
entry->SetDescription( m_DocCtrl->GetValue() );
entry->SetKeyWords( m_KeywordsCtrl->GetValue() );
entry->SetDocFileName( m_DocfileCtrl->GetValue() );
} }
if( m_PartAliasListCtrl->GetStrings() != component->m_AliasList ) if( m_PartAliasListCtrl->GetStrings() != component->m_AliasList )
...@@ -210,6 +196,7 @@ edited!" ), ...@@ -210,6 +196,7 @@ edited!" ),
return; return;
} }
LIB_COMPONENT* component = m_Parent->GetComponent();
m_Parent->GetAliasName().Empty(); m_Parent->GetAliasName().Empty();
if( IsOK( this, _( "Remove all aliases from list?" ) ) ) if( IsOK( this, _( "Remove all aliases from list?" ) ) )
...@@ -217,6 +204,8 @@ edited!" ), ...@@ -217,6 +204,8 @@ edited!" ),
m_PartAliasListCtrl->Clear(); m_PartAliasListCtrl->Clear();
m_ButtonDeleteAllAlias->Enable( false ); m_ButtonDeleteAllAlias->Enable( false );
m_ButtonDeleteOneAlias->Enable( false ); m_ButtonDeleteOneAlias->Enable( false );
if( component )
component->ClearAliasDataDoc();
} }
} }
...@@ -281,6 +270,9 @@ edited!" ), ...@@ -281,6 +270,9 @@ edited!" ),
} }
m_PartAliasListCtrl->Delete( m_PartAliasListCtrl->GetSelection() ); m_PartAliasListCtrl->Delete( m_PartAliasListCtrl->GetSelection() );
LIB_COMPONENT* component = m_Parent->GetComponent();
if( component )
component->RemoveAliasData(aliasname);
if( m_PartAliasListCtrl->IsEmpty() ) if( m_PartAliasListCtrl->IsEmpty() )
{ {
......
...@@ -197,9 +197,12 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC, ...@@ -197,9 +197,12 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
Component = new SCH_COMPONENT( *Entry, GetSheet(), unit, convert, Component = new SCH_COMPONENT( *Entry, GetSheet(), unit, convert,
GetScreen()->m_Curseur, true ); GetScreen()->m_Curseur, true );
// Set the m_ChipName value, from component name in lib, for aliases
// Note if Entry is found, and if Name is an alias of a component,
// alias exists because its root component was found
Component->m_ChipName = Name;
// Set the component value (that can differ from component name in lib, // Set the component value that can differ from component name in lib, for aliases
// for aliases)
Component->GetField( VALUE )->m_Text = Name; Component->GetField( VALUE )->m_Text = Name;
Component->DisplayInfo( this ); Component->DisplayInfo( this );
......
...@@ -180,6 +180,9 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* LibEntry, ...@@ -180,6 +180,9 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* LibEntry,
if( m_component->HasConversion() ) if( m_component->HasConversion() )
m_showDeMorgan = true; m_showDeMorgan = true;
// Collect aliases data and store it in the root component, for edition:
m_component->CollectAliasesData( Library );
GetBaseScreen()->ClrModify(); GetBaseScreen()->ClrModify();
DisplayLibInfos(); DisplayLibInfos();
UpdateAliasSelectList(); UpdateAliasSelectList();
...@@ -279,7 +282,6 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event ) ...@@ -279,7 +282,6 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event )
void WinEDA_LibeditFrame::DisplayCmpDoc() void WinEDA_LibeditFrame::DisplayCmpDoc()
{ {
wxString msg; wxString msg;
LIB_ALIAS* alias = NULL;
ClearMsgPanel(); ClearMsgPanel();
...@@ -291,14 +293,9 @@ void WinEDA_LibeditFrame::DisplayCmpDoc() ...@@ -291,14 +293,9 @@ void WinEDA_LibeditFrame::DisplayCmpDoc()
AppendMsgPanel( _( "Part" ), msg, BLUE, 8 ); AppendMsgPanel( _( "Part" ), msg, BLUE, 8 );
if( m_aliasName.IsEmpty() ) if( m_aliasName.IsEmpty() )
{
msg = _( "None" ); msg = _( "None" );
}
else else
{
msg = m_aliasName; msg = m_aliasName;
alias = m_library->FindAlias( m_aliasName );
}
AppendMsgPanel( _( "Alias" ), msg, RED, 8 ); AppendMsgPanel( _( "Alias" ), msg, RED, 8 );
...@@ -321,19 +318,27 @@ void WinEDA_LibeditFrame::DisplayCmpDoc() ...@@ -321,19 +318,27 @@ void WinEDA_LibeditFrame::DisplayCmpDoc()
AppendMsgPanel( _( "Type" ), msg, MAGENTA, 8 ); AppendMsgPanel( _( "Type" ), msg, MAGENTA, 8 );
if( alias != NULL ) if( m_aliasName.IsEmpty() )
msg = alias->GetDescription();
else
msg = m_component->GetDescription(); msg = m_component->GetDescription();
else
msg = m_component->GetAliasDataDoc( m_aliasName );
AppendMsgPanel( _( "Description" ), msg, CYAN, 8 ); AppendMsgPanel( _( "Description" ), msg, CYAN, 8 );
if( alias != NULL ) if( m_aliasName.IsEmpty() )
msg = alias->GetKeyWords();
else
msg = m_component->GetKeyWords(); msg = m_component->GetKeyWords();
else
msg = m_component->GetAliasDataKeyWords( m_aliasName );
AppendMsgPanel( _( "Key words" ), msg, DARKDARKGRAY ); AppendMsgPanel( _( "Key words" ), msg, DARKDARKGRAY );
if( m_aliasName.IsEmpty() )
msg = m_component->GetDocFileName();
else
msg = m_component->GetAliasDataDocFileName( m_aliasName );
AppendMsgPanel( _( "datasheet" ), msg, DARKDARKGRAY );
} }
......
...@@ -469,10 +469,7 @@ void WinEDA_LibeditFrame::OnUpdateViewDoc( wxUpdateUIEvent& event ) ...@@ -469,10 +469,7 @@ void WinEDA_LibeditFrame::OnUpdateViewDoc( wxUpdateUIEvent& event )
{ {
if( !m_aliasName.IsEmpty() ) if( !m_aliasName.IsEmpty() )
{ {
CMP_LIB_ENTRY* entry = m_library->FindEntry( m_aliasName ); enable = !m_component->GetAliasDataDocFileName(m_aliasName).IsEmpty();
if( entry != NULL )
enable = !entry->GetDocFileName().IsEmpty();
} }
else if( !m_component->GetDocFileName().IsEmpty() ) else if( !m_component->GetDocFileName().IsEmpty() )
{ {
...@@ -582,17 +579,9 @@ void WinEDA_LibeditFrame::OnViewEntryDoc( wxCommandEvent& event ) ...@@ -582,17 +579,9 @@ void WinEDA_LibeditFrame::OnViewEntryDoc( wxCommandEvent& event )
wxString fileName; wxString fileName;
if( !m_aliasName.IsEmpty() ) if( !m_aliasName.IsEmpty() )
{ fileName = m_component->GetAliasDataDocFileName(m_aliasName);
CMP_LIB_ENTRY* entry =
m_library->FindEntry( m_aliasName );
if( entry != NULL )
fileName = entry->GetDocFileName();
}
else else
{
fileName = m_component->GetDocFileName(); fileName = m_component->GetDocFileName();
}
if( !fileName.IsEmpty() ) if( !fileName.IsEmpty() )
GetAssociatedDocument( this, fileName, GetAssociatedDocument( this, fileName,
......
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