Symbol editor: do not disable tools and grey symbols from schematic.

Fixes https://gitlab.com/kicad/code/kicad/issues/6968
This commit is contained in:
Wayne Stambaugh 2021-01-08 18:24:12 -05:00
parent 51f02ecc51
commit 0655f2c436
5 changed files with 95 additions and 50 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* 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
@ -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() );
}

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* 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 <maciej.suminski@cern.ch>
*
@ -340,6 +340,16 @@ public:
void LoadSymbolFromSchematic( const std::unique_ptr<LIB_PART>& 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();

View File

@ -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,59 +65,65 @@ bool SYMBOL_EDITOR_EDIT_TOOL::Init()
return m_isSymbolEditor && static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurPart();
};
auto canEdit =
[&]( const SELECTION& sel )
{
SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( 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::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 );
moveMenu.AddSeparator( 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::paste, canEdit && EE_CONDITIONS::Idle, 300 );
selToolMenu.AddItem( ACTIONS::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 );
selToolMenu.AddSeparator( 400 );
selToolMenu.AddItem( ACTIONS::selectAll, havePartCondition, 400 );

View File

@ -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<SYMBOL_EDIT_FRAME*>( 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();

View File

@ -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<SYMBOL_EDIT_FRAME*>( 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;
}