Add enter/leave sheet to modern toolset.

This commit is contained in:
Jeff Young 2019-04-30 15:46:29 +01:00
parent 423d430b58
commit 35e8a340ca
8 changed files with 77 additions and 88 deletions

View File

@ -256,6 +256,9 @@ void HIERARCHY_NAVIG_DLG::onSelectSheetPath( wxTreeEvent& event )
void SCH_EDIT_FRAME::DisplayCurrentSheet()
{
m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
m_toolManager->RunAction( SCH_ACTIONS::clearSelection, true );
SetRepeatItem( NULL );
ClearMsgPanel();

View File

@ -77,23 +77,8 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
}
}
if( item == NULL )
{
if( g_CurrentSheet->Last() != g_RootSheet )
{
msg = AddHotkeyName( _( "Leave Sheet" ), g_Schematic_Hotkeys_Descr, HK_LEAVE_SHEET );
AddMenuItem( PopMenu, ID_POPUP_SCH_LEAVE_SHEET, msg, KiBitmap( leave_sheet_xpm ) );
}
return true;
}
switch( item->Type() )
{
case SCH_JUNCTION_T:
addJunctionMenuEntries( PopMenu, (SCH_JUNCTION*) item );
break;
case SCH_COMPONENT_T:
AddMenusForComponent( PopMenu, (SCH_COMPONENT*) item, Prj().SchSymbolLibTable() );
break;
@ -170,20 +155,6 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component, SYMBOL_LIB
}
void SCH_EDIT_FRAME::addJunctionMenuEntries( wxMenu* aMenu, SCH_JUNCTION* aJunction )
{
wxString msg;
SCH_SCREEN* screen = GetScreen();
if( !aJunction->IsNew() )
{
if( screen->GetWire( aJunction->GetPosition(), EXCLUDE_END_POINTS_T ) )
AddMenuItem( aMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ),
KiBitmap( break_line_xpm ) );
}
}
void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire, SCH_EDIT_FRAME* frame )
{
wxPoint pos = frame->GetCrossHairPosition();
@ -244,8 +215,6 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
if( !Sheet->GetEditFlags() )
{
AddMenuItem( PopMenu, ID_POPUP_SCH_ENTER_SHEET, _( "Enter Sheet" ),
KiBitmap( enter_sheet_xpm ) );
PopMenu->AppendSeparator();
msg = AddHotkeyName( _( "Select Items On PCB" ), g_Schematic_Hotkeys_Descr,
HK_SELECT_ITEMS_ON_PCB );
@ -263,10 +232,6 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
if( Sheet->HasUndefinedPins() ) // Sheet has pin labels, and can be cleaned
AddMenuItem( PopMenu, ID_POPUP_SCH_CLEANUP_SHEET, _( "Cleanup Sheet Pins" ),
KiBitmap( options_pinsheet_xpm ) );
PopMenu->AppendSeparator();
msg = AddHotkeyName( _( "Delete" ), g_Schematic_Hotkeys_Descr, HK_DELETE );
AddMenuItem( PopMenu, ID_SCH_DELETE, msg, KiBitmap( delete_sheet_xpm ) );
}
}

View File

@ -67,8 +67,6 @@
case ID_POPUP_SCH_RESIZE_SHEET:
case ID_POPUP_IMPORT_HLABEL_TO_SHEETPIN:
case ID_POPUP_SCH_EDIT_CONVERT_CMP:
case ID_POPUP_SCH_ENTER_SHEET:
case ID_POPUP_SCH_LEAVE_SHEET:
case ID_POPUP_SCH_ADD_JUNCTION:
case ID_POPUP_SCH_ADD_LABEL:
/* At this point: Do nothing. these commands do not need to stop the
@ -136,23 +134,6 @@
}
break;
case ID_POPUP_SCH_ENTER_SHEET:
if( item && (item->Type() == SCH_SHEET_T) )
{
g_CurrentSheet->push_back( (SCH_SHEET*) item );
DisplayCurrentSheet();
}
break;
case ID_POPUP_SCH_LEAVE_SHEET:
if( g_CurrentSheet->Last() != g_RootSheet )
{
g_CurrentSheet->pop_back();
DisplayCurrentSheet();
}
break;
default: // Log error:
wxFAIL_MSG( wxString::Format( "Cannot process command event ID %d", event.GetId() ) );
break;

View File

@ -256,6 +256,12 @@ OPT<TOOL_EVENT> SCH_ACTIONS::TranslateLegacyId( int aId )
case ID_HOTKEY_SELECT_CONNECTION:
return SCH_ACTIONS::selectConnection.MakeEvent();
case ID_POPUP_SCH_ENTER_SHEET:
return SCH_ACTIONS::enterSheet.MakeEvent();
case ID_POPUP_SCH_LEAVE_SHEET:
return SCH_ACTIONS::leaveSheet.MakeEvent();
}
return OPT<TOOL_EVENT>();

View File

@ -67,25 +67,6 @@ public:
/// Runs a selection menu to select from a list of items
static TOOL_ACTION selectionMenu;
/* Can we share these with PCBNew?
// Layer control
static TOOL_ACTION layerTop;
static TOOL_ACTION layerInner1;
static TOOL_ACTION layerInner2;
static TOOL_ACTION layerInner3;
static TOOL_ACTION layerInner4;
static TOOL_ACTION layerInner5;
static TOOL_ACTION layerInner6;
static TOOL_ACTION layerBottom;
static TOOL_ACTION layerNext;
static TOOL_ACTION layerPrev;
static TOOL_ACTION layerAlphaInc;
static TOOL_ACTION layerAlphaDec;
static TOOL_ACTION layerToggle;
static TOOL_ACTION layerChanged; // notification
*/
// Locking
static TOOL_ACTION toggleLock;
static TOOL_ACTION lock;
@ -160,6 +141,8 @@ public:
static TOOL_ACTION paste;
// Miscellaneous
static TOOL_ACTION enterSheet;
static TOOL_ACTION leaveSheet;
static TOOL_ACTION switchCursor;
static TOOL_ACTION switchUnits;
static TOOL_ACTION updateUnits;

View File

@ -38,6 +38,7 @@
#include <tools/sch_picker_tool.h>
#include <tools/sch_editor_control.h>
#include <tools/sch_selection_tool.h>
#include <tools/sch_drawing_tool.h>
#include <project.h>
#include <hotkeys.h>
#include <advanced_config.h>
@ -89,6 +90,16 @@ TOOL_ACTION SCH_ACTIONS::editWithSymbolEditor( "eeschema.EditorControl.editWithS
_( "Edit with Symbol Editor" ), _( "Open the symbol editor to edit the symbol" ),
libedit_xpm );
TOOL_ACTION SCH_ACTIONS::enterSheet( "eeschema.EditorControl.enterSheet",
AS_GLOBAL, 0,
_( "Enter Sheet" ), _( "Display the selected sheet's contents in the Eeschema window" ),
enter_sheet_xpm );
TOOL_ACTION SCH_ACTIONS::leaveSheet( "eeschema.EditorControl.leaveSheet",
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_LEAVE_SHEET ),
_( "Leave Sheet" ), _( "Display the parent sheet in the Eeschema window" ),
leave_sheet_xpm );
SCH_EDITOR_CONTROL::SCH_EDITOR_CONTROL() :
TOOL_INTERACTIVE( "eeschema.EditorControl" ),
@ -117,10 +128,15 @@ bool SCH_EDITOR_CONTROL::Init()
return ( m_frame->GetToolId() != ID_NO_TOOL_SELECTED );
};
auto inactiveStateCondition = [ this ] ( const SELECTION& aSel ) {
return ( m_frame->GetToolId() == ID_NO_TOOL_SELECTED && aSel.Size() == 0 );
auto singleSheetCondition = SELECTION_CONDITIONS::Count( 1 )
&& SELECTION_CONDITIONS::OnlyType( SCH_SHEET_T );
auto belowRootSheetCondition = [] ( const SELECTION& aSel ) {
return g_CurrentSheet->Last() != g_RootSheet;
};
auto anySheetCondition = singleSheetCondition || belowRootSheetCondition;
auto& ctxMenu = m_menu.GetMenu();
// "Cancel" goes at the top of the context menu when a tool is active
@ -130,25 +146,27 @@ bool SCH_EDITOR_CONTROL::Init()
// Finally, add the standard zoom & grid items
m_menu.AddStandardSubMenus( m_frame );
/*
auto lockMenu = std::make_shared<LOCK_CONTEXT_MENU>();
lockMenu->SetTool( this );
// Add the SCH control menus to relevant other tools
SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
if( selTool )
{
auto& toolMenu = selTool->GetToolMenu();
auto& menu = toolMenu.GetMenu();
CONDITIONAL_MENU& selToolMenu = selTool->GetToolMenu().GetMenu();
menu.AddSeparator( inactiveStateCondition );
toolMenu.AddSubMenu( lockMenu );
menu.AddMenu( lockMenu.get(), false,
SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::LockableItems ), 200 );
selToolMenu.AddSeparator( anySheetCondition, 600 );
selToolMenu.AddItem( SCH_ACTIONS::enterSheet, singleSheetCondition, 600 );
selToolMenu.AddItem( SCH_ACTIONS::leaveSheet, belowRootSheetCondition, 600 );
}
SCH_DRAWING_TOOL* drawingTool = m_toolMgr->GetTool<SCH_DRAWING_TOOL>();
if( drawingTool )
{
CONDITIONAL_MENU& drawingToolMenu = drawingTool->GetToolMenu().GetMenu();
drawingToolMenu.AddSeparator( belowRootSheetCondition, 600 );
drawingToolMenu.AddItem( SCH_ACTIONS::leaveSheet, belowRootSheetCondition, 600 );
}
*/
return true;
}
@ -680,6 +698,33 @@ int SCH_EDITOR_CONTROL::EditWithSymbolEditor( const TOOL_EVENT& aEvent )
}
int SCH_EDITOR_CONTROL::EnterSheet( const TOOL_EVENT& aEvent )
{
SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
const SELECTION& selection = selTool->RequestSelection( (KICAD_T[]) { SCH_SHEET_T, EOT } );
if( selection.GetSize() == 1 )
{
g_CurrentSheet->push_back( (SCH_SHEET*) selection.GetItem( 0 ) );
m_frame->DisplayCurrentSheet();
}
return 0;
}
int SCH_EDITOR_CONTROL::LeaveSheet( const TOOL_EVENT& aEvent )
{
if( g_CurrentSheet->Last() != g_RootSheet )
{
g_CurrentSheet->pop_back();
m_frame->DisplayCurrentSheet();
}
return 0;
}
void SCH_EDITOR_CONTROL::setTransitions()
{
/*
@ -714,4 +759,7 @@ void SCH_EDITOR_CONTROL::setTransitions()
Go( &SCH_EDITOR_CONTROL::Paste, SCH_ACTIONS::paste.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::EditWithSymbolEditor, SCH_ACTIONS::editWithSymbolEditor.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::EnterSheet, SCH_ACTIONS::enterSheet.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::LeaveSheet, SCH_ACTIONS::leaveSheet.MakeEvent() );
}

View File

@ -85,6 +85,9 @@ public:
int EditWithSymbolEditor( const TOOL_EVENT& aEvent );
int EnterSheet( const TOOL_EVENT& aEvent );
int LeaveSheet( const TOOL_EVENT& aEvent );
private:
///> copy selection to clipboard
bool doCopy();

View File

@ -97,7 +97,7 @@ bool SCH_SELECTION_TOOL::Init()
{
m_frame = getEditFrame<SCH_BASE_FRAME>();
m_menu.GetMenu().AddSeparator( SELECTION_CONDITIONS::NotEmpty, 1000 );
m_menu.GetMenu().AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 );
m_menu.AddStandardSubMenus( m_frame );
return true;