From ed6c68a1e35f68c1d0b1f46715cf7a5ac5032b65 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 22 Nov 2018 21:30:36 +0000 Subject: [PATCH] Clean up handling of component fields. In particular the datasheet field and how its handled with aliases, but also cleaning up duplicated functionality around aliases and libids. --- .../dialogs/dialog_edit_component_in_lib.cpp | 14 +++++-- eeschema/getpart.cpp | 22 +---------- .../netlist_exporter_generic.cpp | 2 +- eeschema/sch_component.cpp | 38 ++++++++----------- eeschema/sch_component.h | 7 ++-- 5 files changed, 34 insertions(+), 49 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.cpp b/eeschema/dialogs/dialog_edit_component_in_lib.cpp index 3b3b81af35..aab619653d 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_lib.cpp @@ -151,9 +151,14 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataToWindow() if( !wxDialog::TransferDataToWindow() ) return false; + LIB_ALIAS* rootAlias = m_libEntry->GetAlias( m_libEntry->GetName() ); + // Push a copy of each field into m_fields m_libEntry->GetFields( *m_fields ); + // Datasheet field is special; grab its value from the docfilename + m_fields->at( DATASHEET ).SetText( rootAlias->GetDocFileName() ); + // The Y axis for components in lib is from bottom to top while the screen axis is top // to bottom: we must change the y coord sign for editing for( size_t i = 0; i < m_fields->size(); ++i ) @@ -170,7 +175,6 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataToWindow() m_SymbolNameCtrl->SetValue( m_libEntry->GetName() ); - LIB_ALIAS* rootAlias = m_libEntry->GetAlias( m_libEntry->GetName() ); m_DescCtrl->SetValue( rootAlias->GetDescription() ); m_KeywordCtrl->SetValue( rootAlias->GetKeyWords() ); @@ -279,6 +283,8 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataFromWindow() if( !Validate() ) return false; + LIB_ALIAS* rootAlias = m_libEntry->GetAlias( m_libEntry->GetName() ); + m_Parent->SaveCopyInUndoList( m_libEntry ); // The Y axis for components in lib is from bottom to top while the screen axis is top @@ -290,13 +296,15 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataFromWindow() m_fields->at( i ).SetPosition( pos ); } + // Datasheet field is special; copy it to the root alias docfilename + rootAlias->SetDocFileName( m_fields->at( DATASHEET ).GetText() ); + m_fields->at( DATASHEET ).SetText( wxEmptyString ); + m_libEntry->SetFields( *m_fields ); // We need to keep the name and the value the same at the moment! SetName( m_libEntry->GetValueField().GetText() ); - LIB_ALIAS* rootAlias = m_libEntry->GetAlias( m_libEntry->GetName() ); - rootAlias->SetDescription( m_DescCtrl->GetValue() ); rootAlias->SetKeyWords( m_KeywordCtrl->GetValue() ); diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 43c3bab116..0a6ca9134e 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -245,14 +245,10 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( const SCHLIB_FILTER* aF if( !part ) return NULL; - SCH_COMPONENT* component = new SCH_COMPONENT( *part, m_CurrentSheet, sel.Unit, sel.Convert, + SCH_COMPONENT* component = new SCH_COMPONENT( *part, libId, m_CurrentSheet, + sel.Unit, sel.Convert, GetCrossHairPosition(), true ); - // Set the m_ChipName value, from component name in lib, for aliases - // Note if part is found, and if name is an alias of a component, - // alias exists because its root component was found - component->SetLibId( libId ); - // Be sure the link to the corresponding LIB_PART is OK: component->Resolve( *Prj().SchSymbolLibTable() ); @@ -265,20 +261,6 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( const SCHLIB_FILTER* aF field->SetText( i.second ); } - // Set the component value that can differ from component name in lib, for aliases - component->GetField( VALUE )->SetText( sel.LibId.GetLibItemName() ); - - // If there is no field defined in the component, copy one over from the library - // ( from the .dcm file ) - // This way the Datasheet field will not be empty and can be changed from the schematic - if( component->GetField( DATASHEET )->GetText().IsEmpty() ) - { - LIB_ALIAS* entry = GetLibAlias( component->GetLibId(), true, true ); - - if( entry && !!entry->GetDocFileName() ) - component->GetField( DATASHEET )->SetText( entry->GetDocFileName() ); - } - MSG_PANEL_ITEMS items; component->SetCurrentSheetPath( &GetCurrentSheet() ); diff --git a/eeschema/netlist_exporters/netlist_exporter_generic.cpp b/eeschema/netlist_exporters/netlist_exporter_generic.cpp index faac2bbfc6..b58aaef49b 100644 --- a/eeschema/netlist_exporters/netlist_exporter_generic.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_generic.cpp @@ -246,7 +246,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents() // We only want the symbol name, not the full LIB_ID. xlibsource->AddAttribute( "part", comp->GetLibId().GetLibItemName() ); - xlibsource->AddAttribute( "description", comp->GetAliasDescription() ); + xlibsource->AddAttribute( "description", comp->GetDescription() ); XNODE* xsheetpath; diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 3a4053d075..82e7f9404e 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -128,15 +128,15 @@ SCH_COMPONENT::SCH_COMPONENT( const wxPoint& aPos, SCH_ITEM* aParent ) : } -SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit, - int convert, const wxPoint& pos, bool setNewItemFlag ) : +SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, LIB_ID aLibId, SCH_SHEET_PATH* sheet, + int unit, int convert, const wxPoint& pos, bool setNewItemFlag ) : SCH_ITEM( NULL, SCH_COMPONENT_T ) { Init( pos ); m_unit = unit; m_convert = convert; - m_lib_id.SetLibItemName( aPart.GetName(), false ); + m_lib_id = aLibId; m_part = aPart.SharedPtr(); m_currentSheetPath = NULL; m_fieldsAutoplaced = AUTOPLACED_NO; @@ -146,25 +146,14 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit, if( setNewItemFlag ) m_Flags = IS_NEW | IS_MOVED; - // Import user defined fields from the library component + // Copy fields from the library component UpdateFields( true, true ); // Update the pin locations UpdatePinCache(); - wxString msg = aPart.GetReferenceField().GetText(); - - if( msg.IsEmpty() ) - msg = wxT( "U" ); - - m_prefix = msg; - - // update the reference -- just the prefix for now. - msg += wxT( "?" ); - SetRef( sheet, msg ); - - // Use the schematic component name instead of the library value field name. - GetField( VALUE )->SetText( GetLibId().GetLibItemName() ); + // Update the reference -- just the prefix for now. + SetRef( sheet, aPart.GetReferenceField().GetText() + wxT( "?" ) ); } @@ -280,7 +269,7 @@ void SCH_COMPONENT::SetLibId( const LIB_ID& aLibId, SYMBOL_LIB_TABLE* aSymLibTab } -wxString SCH_COMPONENT::GetAliasDescription() const +wxString SCH_COMPONENT::GetDescription() const { if( PART_SPTR part = m_part.lock() ) { @@ -296,7 +285,7 @@ wxString SCH_COMPONENT::GetAliasDescription() const } -wxString SCH_COMPONENT::GetAliasDocumentation() const +wxString SCH_COMPONENT::GetDatasheet() const { if( PART_SPTR part = m_part.lock() ) { @@ -1002,8 +991,8 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef ) if( !schField ) { - SCH_FIELD fld( wxPoint( 0, 0 ), GetFieldCount(), this, field.GetName() ); - schField = AddField( fld ); + SCH_FIELD newField( wxPoint( 0, 0 ), GetFieldCount(), this, field.GetName() ); + schField = AddField( newField ); } if( aResetStyle ) @@ -1012,7 +1001,12 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef ) schField->SetTextPos( m_Pos + field.GetTextPos() ); } - schField->SetText( field.GetText() ); + if( idx == VALUE ) + schField->SetText( m_lib_id.GetLibItemName() ); // fetch alias-specific value + else if( idx == DATASHEET ) + schField->SetText( GetDatasheet() ); // fetch alias-specific value + else + schField->SetText( field.GetText() ); } } } diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index 386b197ab0..12021b313e 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -120,6 +120,7 @@ public: * Create schematic component from library component object. * * @param aPart - library part to create schematic component from. + * @param aLibId - libId of alias to create. * @param aSheet - Schematic sheet the component is place into. * @param unit - Part for components that have multiple parts per * package. @@ -128,7 +129,7 @@ public: * @param pos - Position to place new component. * @param setNewItemFlag - Set the component IS_NEW and IS_MOVED flags. */ - SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* aSheet, + SCH_COMPONENT( LIB_PART& aPart, LIB_ID aLibId, SCH_SHEET_PATH* aSheet, int unit = 0, int convert = 0, const wxPoint& pos = wxPoint( 0, 0 ), bool setNewItemFlag = false ); @@ -176,12 +177,12 @@ public: /** * Return information about the aliased parts */ - wxString GetAliasDescription() const; + wxString GetDescription() const; /** * Return the documentation text for the given part alias */ - wxString GetAliasDocumentation() const; + wxString GetDatasheet() const; /** * Assigns the current #LIB_PART from \a aLibs which this symbol is based on.