From f9bbdb31b0ecbf273d088561b75723dc2580f575 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 22 Dec 2020 00:07:01 +0000 Subject: [PATCH] Beginnings of legacy symbol locking. Fixes https://gitlab.com/kicad/code/kicad/issues/5211 --- eeschema/symbol_editor/symbol_edit_frame.cpp | 36 +++++++++++++++++++- eeschema/symbol_editor/symbol_edit_frame.h | 2 ++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index 2fa3bcc7cd..c88d5acaab 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -67,6 +67,7 @@ #include #include #include +#include bool SYMBOL_EDIT_FRAME:: m_showDeMorgan = false; @@ -632,6 +633,20 @@ void SYMBOL_EDIT_FRAME::OnSelectUnit( wxCommandEvent& event ) } +bool SYMBOL_EDIT_FRAME::IsSymbolFromLegacyLibrary() const +{ + if( m_my_part ) + { + SYMBOL_LIB_TABLE_ROW* row = m_libMgr->GetLibrary( m_my_part->GetLibNickname() ); + + if( row && row->GetType() == SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) ) + return true; + } + + return false; +} + + wxString SYMBOL_EDIT_FRAME::GetCurLib() const { wxString libNickname = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_LIB ); @@ -686,6 +701,7 @@ void SYMBOL_EDIT_FRAME::SetCurPart( LIB_PART* aPart, bool aUpdateZoom ) wxString partName = m_my_part ? m_my_part->GetName() : wxString(); bool isAlias = !IsSymbolFromSchematic() && m_my_part && m_my_part->IsAlias(); + bool isLegacy = IsSymbolFromLegacyLibrary(); // retain in case this wxFrame is re-opened later on the same PROJECT Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_PART, partName ); @@ -697,7 +713,7 @@ void SYMBOL_EDIT_FRAME::SetCurPart( LIB_PART* aPart, bool aUpdateZoom ) GetRenderSettings()->m_ShowUnit = m_unit; GetRenderSettings()->m_ShowConvert = m_convert; - GetRenderSettings()->m_ShowDisabled = isAlias; + GetRenderSettings()->m_ShowDisabled = isAlias || isLegacy; GetCanvas()->DisplayComponent( m_my_part ); GetCanvas()->GetView()->HideWorksheet(); GetCanvas()->GetView()->ClearHiddenFlags(); @@ -718,6 +734,24 @@ void SYMBOL_EDIT_FRAME::SetCurPart( LIB_PART* aPart, bool aUpdateZoom ) infobar->RemoveAllButtons(); infobar->ShowMessage( msg, wxICON_INFORMATION ); } + else if( isLegacy ) + { + wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, + _( "Manage symbol libraries" ), + wxEmptyString ); + + button->Bind( wxEVT_COMMAND_HYPERLINK, std::function( + [&]( wxHyperlinkEvent& aEvent ) + { + InvokeSchEditSymbolLibTable( &Kiway(), this ); + } ) ); + + infobar->RemoveAllButtons(); + infobar->AddButton( button ); + infobar->ShowMessage( _( "Symbols in legacy libraries are not editable. Use Manage " + "Symbol Libraries to migrate to current format." ), + wxICON_INFORMATION ); + } else if( isAlias ) { wxString parentPartName = m_my_part->GetParent().lock()->GetName(); diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index 2767521447..19987f55e6 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -274,6 +274,8 @@ public: bool IsSymbolFromSchematic() const { return m_isSymbolFromSchematic; } + bool IsSymbolFromLegacyLibrary() const; + protected: void setupUIConditions() override;