From 0655f2c43648c8499dc0a354352c3af70f46cdb9 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 8 Jan 2021 18:24:12 -0500 Subject: [PATCH] Symbol editor: do not disable tools and grey symbols from schematic. Fixes https://gitlab.com/kicad/code/kicad/issues/6968 --- eeschema/symbol_editor/symbol_edit_frame.cpp | 34 ++++++---- eeschema/symbol_editor/symbol_edit_frame.h | 12 +++- eeschema/tools/symbol_editor_edit_tool.cpp | 66 +++++++++++--------- eeschema/tools/symbol_editor_move_tool.cpp | 16 +++-- eeschema/tools/symbol_editor_pin_tool.cpp | 17 +++-- 5 files changed, 95 insertions(+), 50 deletions(-) diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index a7704c1d35..9e31640a00 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -71,7 +71,7 @@ #include -bool SYMBOL_EDIT_FRAME:: m_showDeMorgan = false; +bool SYMBOL_EDIT_FRAME::m_showDeMorgan = false; BEGIN_EVENT_TABLE( SYMBOL_EDIT_FRAME, EDA_DRAW_FRAME ) @@ -337,8 +337,9 @@ void SYMBOL_EDIT_FRAME::setupUIConditions() auto isEditableCond = [this] ( const SELECTION& ) { - // Only root symbols are editable - return m_my_part && m_my_part->IsRoot() && !IsSymbolFromLegacyLibrary(); + // Only root symbols from the new s-expression libraries or the schematic + // are editable. + return IsSymbolEditable(); }; auto schematicModifiedCond = @@ -460,9 +461,9 @@ void SYMBOL_EDIT_FRAME::setupUIConditions() }; mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) ); - mgr->SetConditions( EE_ACTIONS::symbolProperties, ENABLE( haveSymbolCond ) ); + mgr->SetConditions( EE_ACTIONS::symbolProperties, ENABLE( isEditableCond && haveSymbolCond ) ); mgr->SetConditions( EE_ACTIONS::runERC, ENABLE( haveSymbolCond ) ); - mgr->SetConditions( EE_ACTIONS::pinTable, ENABLE( haveSymbolCond ) ); + mgr->SetConditions( EE_ACTIONS::pinTable, ENABLE( isEditableCond && haveSymbolCond ) ); mgr->SetConditions( EE_ACTIONS::showDeMorganStandard, ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganStandardCond ) ); @@ -477,11 +478,14 @@ void SYMBOL_EDIT_FRAME::setupUIConditions() mgr->SetConditions( ACTIONS::deleteTool, EDIT_TOOL( ACTIONS::deleteTool ) ); mgr->SetConditions( EE_ACTIONS::placeSymbolPin, EDIT_TOOL( EE_ACTIONS::placeSymbolPin ) ); mgr->SetConditions( EE_ACTIONS::placeSymbolText, EDIT_TOOL( EE_ACTIONS::placeSymbolText ) ); - mgr->SetConditions( EE_ACTIONS::drawSymbolRectangle, EDIT_TOOL( EE_ACTIONS::drawSymbolRectangle ) ); - mgr->SetConditions( EE_ACTIONS::drawSymbolCircle, EDIT_TOOL( EE_ACTIONS::drawSymbolCircle ) ); + mgr->SetConditions( EE_ACTIONS::drawSymbolRectangle, + EDIT_TOOL( EE_ACTIONS::drawSymbolRectangle ) ); + mgr->SetConditions( EE_ACTIONS::drawSymbolCircle, + EDIT_TOOL( EE_ACTIONS::drawSymbolCircle ) ); mgr->SetConditions( EE_ACTIONS::drawSymbolArc, EDIT_TOOL( EE_ACTIONS::drawSymbolArc ) ); mgr->SetConditions( EE_ACTIONS::drawSymbolLines, EDIT_TOOL( EE_ACTIONS::drawSymbolLines ) ); - mgr->SetConditions( EE_ACTIONS::placeSymbolAnchor, EDIT_TOOL( EE_ACTIONS::placeSymbolAnchor ) ); + mgr->SetConditions( EE_ACTIONS::placeSymbolAnchor, + EDIT_TOOL( EE_ACTIONS::placeSymbolAnchor ) ); RegisterUIUpdateHandler( ID_LIBEDIT_IMPORT_BODY_BUTT, ENABLE( isEditableCond ) ); RegisterUIUpdateHandler( ID_LIBEDIT_EXPORT_BODY_BUTT, ENABLE( haveSymbolCond ) ); @@ -702,7 +706,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 || isLegacy; + GetRenderSettings()->m_ShowDisabled = ( isAlias || isLegacy ) && !IsSymbolFromSchematic(); GetCanvas()->DisplayComponent( m_my_part ); GetCanvas()->GetView()->HideWorksheet(); GetCanvas()->GetView()->ClearHiddenFlags(); @@ -1109,7 +1113,8 @@ void SYMBOL_EDIT_FRAME::RebuildView() { GetRenderSettings()->m_ShowUnit = m_unit; GetRenderSettings()->m_ShowConvert = m_convert; - GetRenderSettings()->m_ShowDisabled = m_my_part && m_my_part->IsAlias(); + GetRenderSettings()->m_ShowDisabled = + m_my_part && m_my_part->IsAlias() && !IsSymbolFromSchematic(); GetCanvas()->DisplayComponent( m_my_part ); GetCanvas()->GetView()->HideWorksheet(); GetCanvas()->GetView()->ClearHiddenFlags(); @@ -1428,3 +1433,10 @@ bool SYMBOL_EDIT_FRAME::replaceLibTableEntry( const wxString& aLibNickname, return true; } + + +bool SYMBOL_EDIT_FRAME::IsSymbolEditable() const +{ + return m_my_part && m_my_part->IsRoot() && + ( !IsSymbolFromLegacyLibrary() || IsSymbolFromSchematic() ); +} diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index 6fd47f1227..f929be4013 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -3,7 +3,7 @@ * * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2017 CERN * @author Maciej Suminski * @@ -340,6 +340,16 @@ public: void LoadSymbolFromSchematic( const std::unique_ptr& aSymbol, const wxString& aReference, int aUnit, int aConvert ); + /** + * Test if a symbol is loaded and can be edited. + * + * The following conditions are required for a symbol to be editable: + * - The symbol must selected from either a library or the schematic. + * - The symbol must be a root symbol. + * - The symbol must not be from a legacy library. + */ + bool IsSymbolEditable() const; + ///< Restore the empty editor screen, without any part or library selected. void emptyScreen(); diff --git a/eeschema/tools/symbol_editor_edit_tool.cpp b/eeschema/tools/symbol_editor_edit_tool.cpp index 4bde12caac..4d54880eb1 100644 --- a/eeschema/tools/symbol_editor_edit_tool.cpp +++ b/eeschema/tools/symbol_editor_edit_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -65,62 +65,68 @@ bool SYMBOL_EDITOR_EDIT_TOOL::Init() return m_isSymbolEditor && static_cast( m_frame )->GetCurPart(); }; + auto canEdit = + [&]( const SELECTION& sel ) + { + SYMBOL_EDIT_FRAME* editor = static_cast( m_frame ); + wxCHECK( editor, false ); + + return editor->IsSymbolEditable(); + }; + // Add edit actions to the move tool menu - // if( moveTool ) { CONDITIONAL_MENU& moveMenu = moveTool->GetToolMenu().GetMenu(); moveMenu.AddSeparator( 200 ); - moveMenu.AddItem( EE_ACTIONS::rotateCCW, EE_CONDITIONS::NotEmpty, 200 ); - moveMenu.AddItem( EE_ACTIONS::rotateCW, EE_CONDITIONS::NotEmpty, 200 ); - moveMenu.AddItem( EE_ACTIONS::mirrorX, EE_CONDITIONS::NotEmpty, 200 ); - moveMenu.AddItem( EE_ACTIONS::mirrorY, EE_CONDITIONS::NotEmpty, 200 ); - moveMenu.AddItem( ACTIONS::doDelete, EE_CONDITIONS::NotEmpty, 200 ); + moveMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::NotEmpty, 200 ); + moveMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::NotEmpty, 200 ); + moveMenu.AddItem( EE_ACTIONS::mirrorX, canEdit && EE_CONDITIONS::NotEmpty, 200 ); + moveMenu.AddItem( EE_ACTIONS::mirrorY, canEdit && EE_CONDITIONS::NotEmpty, 200 ); + moveMenu.AddItem( ACTIONS::doDelete, canEdit && EE_CONDITIONS::NotEmpty, 200 ); - moveMenu.AddItem( EE_ACTIONS::properties, EE_CONDITIONS::Count( 1 ), 200 ); + moveMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 ); moveMenu.AddSeparator( 300 ); - moveMenu.AddItem( ACTIONS::cut, EE_CONDITIONS::IdleSelection, 300 ); - moveMenu.AddItem( ACTIONS::copy, EE_CONDITIONS::IdleSelection, 300 ); - moveMenu.AddItem( ACTIONS::duplicate, EE_CONDITIONS::NotEmpty, 300 ); + moveMenu.AddItem( ACTIONS::cut, EE_CONDITIONS::IdleSelection, 300 ); + moveMenu.AddItem( ACTIONS::copy, EE_CONDITIONS::IdleSelection, 300 ); + moveMenu.AddItem( ACTIONS::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 ); moveMenu.AddSeparator( 400 ); - moveMenu.AddItem( ACTIONS::selectAll, havePartCondition, 400 ); + moveMenu.AddItem( ACTIONS::selectAll, havePartCondition, 400 ); } // Add editing actions to the drawing tool menu - // CONDITIONAL_MENU& drawMenu = drawingTools->GetToolMenu().GetMenu(); drawMenu.AddSeparator( 200 ); - drawMenu.AddItem( EE_ACTIONS::rotateCCW, EE_CONDITIONS::IdleSelection, 200 ); - drawMenu.AddItem( EE_ACTIONS::rotateCW, EE_CONDITIONS::IdleSelection, 200 ); - drawMenu.AddItem( EE_ACTIONS::mirrorX, EE_CONDITIONS::IdleSelection, 200 ); - drawMenu.AddItem( EE_ACTIONS::mirrorY, EE_CONDITIONS::IdleSelection, 200 ); + drawMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::IdleSelection, 200 ); + drawMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::IdleSelection, 200 ); + drawMenu.AddItem( EE_ACTIONS::mirrorX, canEdit && EE_CONDITIONS::IdleSelection, 200 ); + drawMenu.AddItem( EE_ACTIONS::mirrorY, canEdit && EE_CONDITIONS::IdleSelection, 200 ); - drawMenu.AddItem( EE_ACTIONS::properties, EE_CONDITIONS::Count( 1 ), 200 ); + drawMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 ); // Add editing actions to the selection tool menu - // CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu(); - selToolMenu.AddItem( EE_ACTIONS::rotateCCW, EE_CONDITIONS::NotEmpty, 200 ); - selToolMenu.AddItem( EE_ACTIONS::rotateCW, EE_CONDITIONS::NotEmpty, 200 ); - selToolMenu.AddItem( EE_ACTIONS::mirrorX, EE_CONDITIONS::NotEmpty, 200 ); - selToolMenu.AddItem( EE_ACTIONS::mirrorY, EE_CONDITIONS::NotEmpty, 200 ); - selToolMenu.AddItem( ACTIONS::doDelete, EE_CONDITIONS::NotEmpty, 200 ); + selToolMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::NotEmpty, 200 ); + selToolMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::NotEmpty, 200 ); + selToolMenu.AddItem( EE_ACTIONS::mirrorX, canEdit && EE_CONDITIONS::NotEmpty, 200 ); + selToolMenu.AddItem( EE_ACTIONS::mirrorY, canEdit && EE_CONDITIONS::NotEmpty, 200 ); + selToolMenu.AddItem( ACTIONS::doDelete, canEdit && EE_CONDITIONS::NotEmpty, 200 ); - selToolMenu.AddItem( EE_ACTIONS::properties, EE_CONDITIONS::Count( 1 ), 200 ); + selToolMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 ); selToolMenu.AddSeparator( 300 ); - selToolMenu.AddItem( ACTIONS::cut, EE_CONDITIONS::IdleSelection, 300 ); - selToolMenu.AddItem( ACTIONS::copy, EE_CONDITIONS::IdleSelection, 300 ); - selToolMenu.AddItem( ACTIONS::paste, EE_CONDITIONS::Idle, 300 ); - selToolMenu.AddItem( ACTIONS::duplicate, EE_CONDITIONS::NotEmpty, 300 ); + selToolMenu.AddItem( ACTIONS::cut, EE_CONDITIONS::IdleSelection, 300 ); + selToolMenu.AddItem( ACTIONS::copy, EE_CONDITIONS::IdleSelection, 300 ); + selToolMenu.AddItem( ACTIONS::paste, canEdit && EE_CONDITIONS::Idle, 300 ); + selToolMenu.AddItem( ACTIONS::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 ); selToolMenu.AddSeparator( 400 ); - selToolMenu.AddItem( ACTIONS::selectAll, havePartCondition, 400 ); + selToolMenu.AddItem( ACTIONS::selectAll, havePartCondition, 400 ); return true; } diff --git a/eeschema/tools/symbol_editor_move_tool.cpp b/eeschema/tools/symbol_editor_move_tool.cpp index 57bbfdc40c..c27271decd 100644 --- a/eeschema/tools/symbol_editor_move_tool.cpp +++ b/eeschema/tools/symbol_editor_move_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -48,7 +48,16 @@ bool SYMBOL_EDITOR_MOVE_TOOL::Init() // CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu(); - selToolMenu.AddItem( EE_ACTIONS::move, EE_CONDITIONS::IdleSelection, 150 ); + auto canEdit = + [&]( const SELECTION& sel ) + { + SYMBOL_EDIT_FRAME* editor = static_cast( m_frame ); + wxCHECK( editor, false ); + + return editor->IsSymbolEditable(); + }; + + selToolMenu.AddItem( EE_ACTIONS::move, canEdit && EE_CONDITIONS::IdleSelection, 150 ); return true; } @@ -77,8 +86,7 @@ int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) EE_SELECTION& selection = m_selectionTool->RequestSelection(); bool unselect = selection.IsHover(); - if( !m_frame->GetCurPart() || m_frame->GetCurPart()->IsAlias() - || selection.Empty() || m_moveInProgress ) + if( !m_frame->IsSymbolEditable() || selection.Empty() || m_moveInProgress ) return 0; std::string tool = aEvent.GetCommandStr().get(); diff --git a/eeschema/tools/symbol_editor_pin_tool.cpp b/eeschema/tools/symbol_editor_pin_tool.cpp index 805f8dd276..6cbe5d3180 100644 --- a/eeschema/tools/symbol_editor_pin_tool.cpp +++ b/eeschema/tools/symbol_editor_pin_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -93,14 +93,23 @@ bool SYMBOL_EDITOR_PIN_TOOL::Init() { EE_TOOL_BASE::Init(); + auto canEdit = + [&]( const SELECTION& sel ) + { + SYMBOL_EDIT_FRAME* editor = static_cast( m_frame ); + wxCHECK( editor, false ); + + return editor->IsSymbolEditable(); + }; + auto singlePinCondition = EE_CONDITIONS::Count( 1 ) && EE_CONDITIONS::OnlyType( LIB_PIN_T ); CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu(); selToolMenu.AddSeparator( 400 ); - selToolMenu.AddItem( EE_ACTIONS::pushPinLength, singlePinCondition, 400 ); - selToolMenu.AddItem( EE_ACTIONS::pushPinNameSize, singlePinCondition, 400 ); - selToolMenu.AddItem( EE_ACTIONS::pushPinNumSize, singlePinCondition, 400 ); + selToolMenu.AddItem( EE_ACTIONS::pushPinLength, canEdit && singlePinCondition, 400 ); + selToolMenu.AddItem( EE_ACTIONS::pushPinNameSize, canEdit && singlePinCondition, 400 ); + selToolMenu.AddItem( EE_ACTIONS::pushPinNumSize, canEdit && singlePinCondition, 400 ); return true; }