Improve IsSymbolEditable to differentiate fields.
Fields are editable in Aliases, but still not in Legacy libraries, locked libraries, etc. Fixes https://gitlab.com/kicad/code/kicad/issues/7175
This commit is contained in:
parent
1dc0ef01b3
commit
a0b9b0c3ee
|
@ -44,7 +44,7 @@ DIALOG_LIB_EDIT_DRAW_ITEM::DIALOG_LIB_EDIT_DRAW_ITEM( SYMBOL_EDIT_FRAME* aParent
|
|||
// Required under wxGTK if we want to dismiss the dialog with the ESC key
|
||||
SetFocus();
|
||||
|
||||
if( !aParent->IsSymbolEditable() )
|
||||
if( !aParent->IsSymbolEditable() || aParent->IsSymbolAlias() )
|
||||
{
|
||||
m_sdbSizerCancel->SetDefault();
|
||||
m_sdbSizerOK->SetLabel( _( "Read Only" ) );
|
||||
|
|
|
@ -490,7 +490,7 @@ DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( SYMBOL_EDIT_FRAME* parent,
|
|||
GetSizer()->SetSizeHints(this);
|
||||
Centre();
|
||||
|
||||
if( !parent->IsSymbolEditable() )
|
||||
if( !parent->IsSymbolEditable() || parent->IsSymbolAlias() )
|
||||
{
|
||||
m_ButtonsCancel->SetDefault();
|
||||
m_ButtonsOK->SetLabel( _( "Read Only" ) );
|
||||
|
|
|
@ -52,7 +52,7 @@ DIALOG_LIB_EDIT_TEXT::DIALOG_LIB_EDIT_TEXT( SYMBOL_EDIT_FRAME* aParent, LIB_TEXT
|
|||
SetInitialFocus( m_TextCtrl );
|
||||
m_StyledTextCtrl->Show( false );
|
||||
|
||||
if( !aParent->IsSymbolEditable() )
|
||||
if( !aParent->IsSymbolEditable() || aParent->IsSymbolAlias() )
|
||||
{
|
||||
m_sdbSizerButtonsCancel->SetDefault();
|
||||
m_sdbSizerButtonsOK->SetLabel( _( "Read Only" ) );
|
||||
|
|
|
@ -74,6 +74,7 @@ SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() :
|
|||
m_ShowHiddenPins( true ),
|
||||
m_ShowPinsElectricalType( true ),
|
||||
m_ShowDisabled( false ),
|
||||
m_ShowGraphicsDisabled( false ),
|
||||
m_ShowUmbilicals( true ),
|
||||
m_OverrideItemColors( false ),
|
||||
m_TextOffsetRatio( 0.08 ),
|
||||
|
@ -309,8 +310,11 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDr
|
|||
color = m_schSettings.GetLayerColor( LAYER_SELECTION_SHADOWS ).WithAlpha( 0.8 );
|
||||
}
|
||||
|
||||
if( m_schSettings.m_ShowDisabled )
|
||||
if( m_schSettings.m_ShowDisabled
|
||||
|| ( m_schSettings.m_ShowGraphicsDisabled && aItem->Type() != LIB_FIELD_T ) )
|
||||
{
|
||||
color = color.Darken( 0.5f );
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
|
|
@ -112,6 +112,7 @@ public:
|
|||
bool m_ShowHiddenPins;
|
||||
bool m_ShowPinsElectricalType;
|
||||
bool m_ShowDisabled;
|
||||
bool m_ShowGraphicsDisabled;
|
||||
bool m_ShowUmbilicals;
|
||||
|
||||
bool m_OverrideItemColors;
|
||||
|
|
|
@ -336,7 +336,7 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
|
|||
{
|
||||
// Only root symbols from the new s-expression libraries or the schematic
|
||||
// are editable.
|
||||
return IsSymbolEditable();
|
||||
return IsSymbolEditable() && !IsSymbolAlias();
|
||||
};
|
||||
|
||||
auto schematicModifiedCond =
|
||||
|
@ -710,8 +710,6 @@ void SYMBOL_EDIT_FRAME::SetCurPart( LIB_PART* aPart, bool aUpdateZoom )
|
|||
m_treePane->GetLibTree()->Unselect();
|
||||
|
||||
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 );
|
||||
|
@ -723,7 +721,8 @@ 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 ) && !IsSymbolFromSchematic();
|
||||
GetRenderSettings()->m_ShowDisabled = IsSymbolFromLegacyLibrary() && !IsSymbolFromSchematic();
|
||||
GetRenderSettings()->m_ShowGraphicsDisabled = IsSymbolAlias() && !IsSymbolFromSchematic();
|
||||
GetCanvas()->DisplayComponent( m_my_part );
|
||||
GetCanvas()->GetView()->HideWorksheet();
|
||||
GetCanvas()->GetView()->ClearHiddenFlags();
|
||||
|
@ -744,7 +743,7 @@ void SYMBOL_EDIT_FRAME::SetCurPart( LIB_PART* aPart, bool aUpdateZoom )
|
|||
infobar->RemoveAllButtons();
|
||||
infobar->ShowMessage( msg, wxICON_INFORMATION );
|
||||
}
|
||||
else if( isLegacy )
|
||||
else if( IsSymbolFromLegacyLibrary() )
|
||||
{
|
||||
wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY,
|
||||
_( "Manage symbol libraries" ),
|
||||
|
@ -762,7 +761,7 @@ void SYMBOL_EDIT_FRAME::SetCurPart( LIB_PART* aPart, bool aUpdateZoom )
|
|||
"Symbol Libraries to migrate to current format." ),
|
||||
wxICON_INFORMATION );
|
||||
}
|
||||
else if( isAlias )
|
||||
else if( IsSymbolAlias() )
|
||||
{
|
||||
wxString parentPartName = m_my_part->GetParent().lock()->GetName();
|
||||
wxString msg;
|
||||
|
@ -1121,8 +1120,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() && !IsSymbolFromSchematic();
|
||||
GetRenderSettings()->m_ShowDisabled = IsSymbolFromLegacyLibrary() && !IsSymbolFromSchematic();
|
||||
GetRenderSettings()->m_ShowGraphicsDisabled = IsSymbolAlias() && !IsSymbolFromSchematic();
|
||||
GetCanvas()->DisplayComponent( m_my_part );
|
||||
GetCanvas()->GetView()->HideWorksheet();
|
||||
GetCanvas()->GetView()->ClearHiddenFlags();
|
||||
|
@ -1441,8 +1440,13 @@ bool SYMBOL_EDIT_FRAME::replaceLibTableEntry( const wxString& aLibNickname,
|
|||
}
|
||||
|
||||
|
||||
bool SYMBOL_EDIT_FRAME::IsSymbolAlias() const
|
||||
{
|
||||
return m_my_part && !m_my_part->IsRoot();
|
||||
}
|
||||
|
||||
|
||||
bool SYMBOL_EDIT_FRAME::IsSymbolEditable() const
|
||||
{
|
||||
return m_my_part && m_my_part->IsRoot() &&
|
||||
( !IsSymbolFromLegacyLibrary() || IsSymbolFromSchematic() );
|
||||
return m_my_part && ( !IsSymbolFromLegacyLibrary() || IsSymbolFromSchematic() );
|
||||
}
|
||||
|
|
|
@ -342,11 +342,15 @@ public:
|
|||
*
|
||||
* 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.
|
||||
*
|
||||
* Note that many things are not editable in a non-root symbol (ie: an alias), but others
|
||||
* are so this routine no longer returns false for an alias.
|
||||
*/
|
||||
bool IsSymbolEditable() const;
|
||||
|
||||
bool IsSymbolAlias() const;
|
||||
|
||||
///< Restore the empty editor screen, without any part or library selected.
|
||||
void emptyScreen();
|
||||
|
||||
|
|
|
@ -71,7 +71,19 @@ bool SYMBOL_EDITOR_EDIT_TOOL::Init()
|
|||
SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
||||
wxCHECK( editor, false );
|
||||
|
||||
return editor->IsSymbolEditable();
|
||||
if( !editor->IsSymbolEditable() )
|
||||
return false;
|
||||
|
||||
if( editor->IsSymbolAlias() )
|
||||
{
|
||||
for( EDA_ITEM* item : sel )
|
||||
{
|
||||
if( item->Type() != LIB_FIELD_T )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// Add edit actions to the move tool menu
|
||||
|
|
|
@ -48,16 +48,28 @@ bool SYMBOL_EDITOR_MOVE_TOOL::Init()
|
|||
//
|
||||
CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
|
||||
|
||||
auto canEdit =
|
||||
auto canMove =
|
||||
[&]( const SELECTION& sel )
|
||||
{
|
||||
SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
||||
wxCHECK( editor, false );
|
||||
|
||||
return editor->IsSymbolEditable();
|
||||
if( !editor->IsSymbolEditable() )
|
||||
return false;
|
||||
|
||||
if( editor->IsSymbolAlias() )
|
||||
{
|
||||
for( EDA_ITEM* item : sel )
|
||||
{
|
||||
if( item->Type() != LIB_FIELD_T )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
selToolMenu.AddItem( EE_ACTIONS::move, canEdit && EE_CONDITIONS::IdleSelection, 150 );
|
||||
selToolMenu.AddItem( EE_ACTIONS::move, canMove && EE_CONDITIONS::IdleSelection, 150 );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -77,13 +89,17 @@ void SYMBOL_EDITOR_MOVE_TOOL::Reset( RESET_REASON aReason )
|
|||
|
||||
int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
static KICAD_T fieldsOnly[] = { LIB_FIELD_T, EOT };
|
||||
|
||||
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
||||
|
||||
m_anchorPos = { 0, 0 };
|
||||
|
||||
// Be sure that there is at least one item that we can move. If there's no selection try
|
||||
// looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection).
|
||||
EE_SELECTION& selection = m_selectionTool->RequestSelection();
|
||||
EE_SELECTION& selection = m_frame->IsSymbolAlias()
|
||||
? m_selectionTool->RequestSelection( fieldsOnly )
|
||||
: m_selectionTool->RequestSelection();
|
||||
bool unselect = selection.IsHover();
|
||||
|
||||
if( !m_frame->IsSymbolEditable() || selection.Empty() || m_moveInProgress )
|
||||
|
|
|
@ -99,7 +99,7 @@ bool SYMBOL_EDITOR_PIN_TOOL::Init()
|
|||
SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
|
||||
wxCHECK( editor, false );
|
||||
|
||||
return editor->IsSymbolEditable();
|
||||
return editor->IsSymbolEditable() && !editor->IsSymbolAlias();
|
||||
};
|
||||
|
||||
auto singlePinCondition = EE_CONDITIONS::Count( 1 ) && EE_CONDITIONS::OnlyType( LIB_PIN_T );
|
||||
|
|
Loading…
Reference in New Issue