Schematic: make menu bar rotation items conditional

Also fix some items not getting a context menu rotate action.
This commit is contained in:
Mike Williams 2022-12-27 13:22:58 -05:00
parent 438c4b58a3
commit f1fab140a1
3 changed files with 21 additions and 30 deletions

View File

@ -414,6 +414,16 @@ void SCH_EDIT_FRAME::setupUIConditions()
return m_auimgr.GetPane( SchematicHierarchyPaneName() ).IsShown();
};
auto orientCondition =
[]( const SELECTION& aSel )
{
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
return false;
return SELECTION_CONDITIONS::HasTypes( SCH_EDIT_TOOL::RotatableItems )( aSel );
};
#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
#define CHECK( x ) ACTION_CONDITIONS().Check( x )
@ -443,10 +453,10 @@ void SCH_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::duplicate, ENABLE( hasElements ) );
mgr->SetConditions( ACTIONS::selectAll, ENABLE( hasElements ) );
mgr->SetConditions( EE_ACTIONS::rotateCW, ENABLE( hasElements ) );
mgr->SetConditions( EE_ACTIONS::rotateCCW, ENABLE( hasElements ) );
mgr->SetConditions( EE_ACTIONS::mirrorH, ENABLE( hasElements ) );
mgr->SetConditions( EE_ACTIONS::mirrorV, ENABLE( hasElements ) );
mgr->SetConditions( EE_ACTIONS::rotateCW, ENABLE( orientCondition ) );
mgr->SetConditions( EE_ACTIONS::rotateCCW, ENABLE( orientCondition ) );
mgr->SetConditions( EE_ACTIONS::mirrorH, ENABLE( orientCondition ) );
mgr->SetConditions( EE_ACTIONS::mirrorV, ENABLE( orientCondition ) );
mgr->SetConditions( ACTIONS::zoomTool,
CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );

View File

@ -193,29 +193,10 @@ bool SCH_EDIT_TOOL::Init()
auto orientCondition =
[]( const SELECTION& aSel )
{
if( aSel.Empty() )
return false;
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
return false;
if( aSel.GetSize() > 1 )
return true;
SCH_ITEM* item = (SCH_ITEM*) aSel.Front();
switch( item->Type() )
{
case SCH_MARKER_T:
case SCH_JUNCTION_T:
case SCH_NO_CONNECT_T:
case SCH_PIN_T:
return false;
case SCH_LINE_T:
return item->GetLayer() != LAYER_WIRE && item->GetLayer() != LAYER_BUS;
default:
return true;
}
return SELECTION_CONDITIONS::HasTypes( SCH_EDIT_TOOL::RotatableItems )( aSel );
};
auto propertiesCondition =
@ -510,7 +491,7 @@ bool SCH_EDIT_TOOL::Init()
}
const std::vector<KICAD_T> rotatableItems = {
const std::vector<KICAD_T> SCH_EDIT_TOOL::RotatableItems = {
SCH_SHAPE_T,
SCH_TEXT_T,
SCH_TEXTBOX_T,
@ -526,15 +507,13 @@ const std::vector<KICAD_T> rotatableItems = {
SCH_BUS_BUS_ENTRY_T,
SCH_BUS_WIRE_ENTRY_T,
SCH_LINE_T,
SCH_JUNCTION_T,
SCH_NO_CONNECT_T
};
int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
{
bool clockwise = ( aEvent.Matches( EE_ACTIONS::rotateCW.MakeEvent() ) );
EE_SELECTION& selection = m_selectionTool->RequestSelection( rotatableItems );
EE_SELECTION& selection = m_selectionTool->RequestSelection( RotatableItems );
if( selection.GetSize() == 0 )
return 0;
@ -797,7 +776,7 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
{
EE_SELECTION& selection = m_selectionTool->RequestSelection( rotatableItems );
EE_SELECTION& selection = m_selectionTool->RequestSelection( RotatableItems );
if( selection.GetSize() == 0 )
return 0;
@ -1447,7 +1426,7 @@ int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent )
int SCH_EDIT_TOOL::AutoplaceFields( const TOOL_EVENT& aEvent )
{
EE_SELECTION& selection = m_selectionTool->RequestSelection( rotatableItems );
EE_SELECTION& selection = m_selectionTool->RequestSelection( RotatableItems );
SCH_ITEM* head = static_cast<SCH_ITEM*>( selection.Front() );
bool moving = head && head->IsMoving();

View File

@ -39,6 +39,8 @@ public:
SCH_EDIT_TOOL();
~SCH_EDIT_TOOL() override { }
static const std::vector<KICAD_T> RotatableItems;
/// @copydoc TOOL_INTERACTIVE::Init()
bool Init() override;