Browse Source

swapping: don't show when we can't swap

master
Mike Williams 2 weeks ago
parent
commit
9f201972a6
  1. 48
      eeschema/tools/sch_edit_tool.cpp
  2. 1
      eeschema/tools/sch_edit_tool.h
  3. 31
      eeschema/tools/symbol_editor_edit_tool.cpp
  4. 2
      eeschema/tools/symbol_editor_edit_tool.h

48
eeschema/tools/sch_edit_tool.cpp

@ -398,6 +398,8 @@ bool SCH_EDIT_TOOL::Init()
return SELECTION_CONDITIONS::HasTypes( SCH_EDIT_TOOL::RotatableItems )( aSel );
};
const auto swapSelectionCondition = S_C::OnlyTypes( SwappableItems ) && SELECTION_CONDITIONS::MoreThan( 1 );
auto propertiesCondition =
[this]( const SELECTION& aSel )
{
@ -684,7 +686,7 @@ bool SCH_EDIT_TOOL::Init()
moveMenu.AddMenu( makeTransformMenu(), orientCondition, 200 );
moveMenu.AddMenu( makeAttributesMenu(), S_C::HasType( SCH_SYMBOL_T ), 200 );
moveMenu.AddItem( SCH_ACTIONS::swap, SELECTION_CONDITIONS::MoreThan( 1 ), 200);
moveMenu.AddItem( SCH_ACTIONS::swap, swapSelectionCondition, 200 );
moveMenu.AddItem( SCH_ACTIONS::properties, propertiesCondition, 200 );
moveMenu.AddMenu( makeEditFieldsMenu(), S_C::SingleSymbol, 200 );
@ -735,7 +737,7 @@ bool SCH_EDIT_TOOL::Init()
selToolMenu.AddMenu( makeTransformMenu(), orientCondition, 200 );
selToolMenu.AddMenu( makeAttributesMenu(), S_C::HasType( SCH_SYMBOL_T ), 200 );
selToolMenu.AddItem( SCH_ACTIONS::swap, SELECTION_CONDITIONS::MoreThan( 1 ), 200 );
selToolMenu.AddItem( SCH_ACTIONS::swap, swapSelectionCondition, 200 );
selToolMenu.AddItem( SCH_ACTIONS::properties, propertiesCondition, 200 );
selToolMenu.AddMenu( makeEditFieldsMenu(), S_C::SingleSymbol, 200 );
selToolMenu.AddItem( SCH_ACTIONS::autoplaceFields, autoplaceCondition, 200 );
@ -799,6 +801,25 @@ const std::vector<KICAD_T> SCH_EDIT_TOOL::RotatableItems = {
};
const std::vector<KICAD_T> SCH_EDIT_TOOL::SwappableItems = {
SCH_SHAPE_T,
SCH_RULE_AREA_T,
SCH_TEXT_T,
SCH_TEXTBOX_T,
SCH_LABEL_T,
SCH_SHEET_PIN_T,
SCH_GLOBAL_LABEL_T,
SCH_HIER_LABEL_T,
SCH_DIRECTIVE_LABEL_T,
SCH_FIELD_T,
SCH_SYMBOL_T,
SCH_SHEET_T,
SCH_BITMAP_T,
SCH_JUNCTION_T,
SCH_NO_CONNECT_T
};
int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
{
bool clockwise = ( aEvent.Matches( SCH_ACTIONS::rotateCW.MakeEvent() ) );
@ -1287,27 +1308,6 @@ int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
return 0;
}
const std::vector<KICAD_T> swappableItems = {
SCH_SHAPE_T,
SCH_RULE_AREA_T,
SCH_TEXT_T,
SCH_TEXTBOX_T,
SCH_LABEL_T,
SCH_SHEET_PIN_T,
SCH_GLOBAL_LABEL_T,
SCH_HIER_LABEL_T,
SCH_DIRECTIVE_LABEL_T,
SCH_FIELD_T,
SCH_SYMBOL_T,
SCH_SHEET_T,
SCH_BITMAP_T,
SCH_JUNCTION_T,
SCH_NO_CONNECT_T
};
/**
* Swap the positions of the fields in the two lists, aAFields and aBFields,
* relative to their parent positions.
@ -1394,7 +1394,7 @@ static void swapFieldPositionsWithMatching( std::vector<SCH_FIELD>& aAFields,
int SCH_EDIT_TOOL::Swap( const TOOL_EVENT& aEvent )
{
SCH_SELECTION& selection = m_selectionTool->RequestSelection( swappableItems );
SCH_SELECTION& selection = m_selectionTool->RequestSelection( SwappableItems );
std::vector<EDA_ITEM*> sorted = selection.GetItemsSortedBySelectionOrder();
if( selection.Size() < 2 )

1
eeschema/tools/sch_edit_tool.h

@ -35,6 +35,7 @@ public:
~SCH_EDIT_TOOL() = default;
static const std::vector<KICAD_T> RotatableItems;
static const std::vector<KICAD_T> SwappableItems;
/// @copydoc TOOL_INTERACTIVE::Init()
bool Init() override;

31
eeschema/tools/symbol_editor_edit_tool.cpp

@ -57,6 +57,16 @@ SYMBOL_EDITOR_EDIT_TOOL::SYMBOL_EDITOR_EDIT_TOOL() :
}
const std::vector<KICAD_T> SYMBOL_EDITOR_EDIT_TOOL::SwappableItems = {
LIB_SYMBOL_T, // Allows swapping the anchor
SCH_PIN_T,
SCH_SHAPE_T,
SCH_TEXT_T,
SCH_TEXTBOX_T,
SCH_FIELD_T,
};
bool SYMBOL_EDITOR_EDIT_TOOL::Init()
{
SCH_TOOL_BASE::Init();
@ -90,6 +100,9 @@ bool SYMBOL_EDITOR_EDIT_TOOL::Init()
return true;
};
auto swapSelectionCondition =
canEdit && SCH_CONDITIONS::OnlyTypes( SwappableItems ) && SELECTION_CONDITIONS::MoreThan( 1 );
const auto canCopyText = SCH_CONDITIONS::OnlyTypes( {
SCH_TEXT_T,
SCH_TEXTBOX_T,
@ -175,7 +188,7 @@ bool SYMBOL_EDITOR_EDIT_TOOL::Init()
moveMenu.AddItem( SCH_ACTIONS::mirrorV, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
moveMenu.AddItem( SCH_ACTIONS::mirrorH, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
moveMenu.AddItem( SCH_ACTIONS::swap, canEdit && SELECTION_CONDITIONS::MoreThan( 1 ), 200);
moveMenu.AddItem( SCH_ACTIONS::swap, swapSelectionCondition, 200 );
moveMenu.AddItem( SCH_ACTIONS::properties, canEdit && SCH_CONDITIONS::Count( 1 ), 200 );
moveMenu.AddSeparator( 300 );
@ -209,7 +222,7 @@ bool SYMBOL_EDITOR_EDIT_TOOL::Init()
selToolMenu.AddItem( SCH_ACTIONS::mirrorV, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
selToolMenu.AddItem( SCH_ACTIONS::mirrorH, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
selToolMenu.AddItem( SCH_ACTIONS::swap, canEdit && SELECTION_CONDITIONS::MoreThan( 1 ), 200 );
selToolMenu.AddItem( SCH_ACTIONS::swap, swapSelectionCondition, 200 );
selToolMenu.AddItem( SCH_ACTIONS::properties, canEdit && SCH_CONDITIONS::Count( 1 ), 200 );
selToolMenu.AddSeparator( 250 );
@ -356,21 +369,9 @@ int SYMBOL_EDITOR_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
return 0;
}
const std::vector<KICAD_T> swappableItems = {
LIB_SYMBOL_T, // Allows swapping the anchor
SCH_PIN_T,
SCH_SHAPE_T,
SCH_TEXT_T,
SCH_TEXTBOX_T,
SCH_FIELD_T,
};
int SYMBOL_EDITOR_EDIT_TOOL::Swap( const TOOL_EVENT& aEvent )
{
SCH_SELECTION& selection = m_selectionTool->RequestSelection( swappableItems );
SCH_SELECTION& selection = m_selectionTool->RequestSelection( SwappableItems );
std::vector<EDA_ITEM*> sorted = selection.GetItemsSortedBySelectionOrder();
if( selection.Size() < 2 )

2
eeschema/tools/symbol_editor_edit_tool.h

@ -38,6 +38,8 @@ public:
SYMBOL_EDITOR_EDIT_TOOL();
~SYMBOL_EDITOR_EDIT_TOOL() = default;
static const std::vector<KICAD_T> SwappableItems;
/// @copydoc TOOL_INTERACTIVE::Init()
bool Init() override;

Loading…
Cancel
Save