From 7c25001622b619d8ffbec9ad5cca51438f522ebf Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 17 May 2019 16:16:13 +0100 Subject: [PATCH] Implement immediate actions for adding and importing sheet pins. Fixes: lp:1829314 * https://bugs.launchpad.net/kicad/+bug/1829314 --- eeschema/tools/ee_actions.h | 2 + eeschema/tools/ee_selection_tool.cpp | 17 ++++---- eeschema/tools/sch_drawing_tools.cpp | 60 +++++++++++++++++++++++++++- eeschema/tools/sch_drawing_tools.h | 1 + eeschema/tools/sch_edit_tool.cpp | 13 +++--- 5 files changed, 77 insertions(+), 16 deletions(-) diff --git a/eeschema/tools/ee_actions.h b/eeschema/tools/ee_actions.h index 49d5ad6a35..9e7bb72a69 100644 --- a/eeschema/tools/ee_actions.h +++ b/eeschema/tools/ee_actions.h @@ -133,6 +133,8 @@ public: static TOOL_ACTION addLabel; static TOOL_ACTION addGlobalLabel; static TOOL_ACTION addHierLabel; + static TOOL_ACTION addSheetPin; + static TOOL_ACTION addImportedSheetPin; static TOOL_ACTION toShapeSlash; static TOOL_ACTION toShapeBackslash; static TOOL_ACTION toLabel; diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index acb6b79b6a..fd5c8f36dc 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -225,14 +225,15 @@ bool EE_SELECTION_TOOL::Init() menu.AddItem( EE_ACTIONS::finishBus, SCH_WIRE_BUS_TOOL::IsDrawingBus, 100 ); menu.AddSeparator( EE_CONDITIONS::NotEmpty, 200 ); - menu.AddItem( EE_ACTIONS::selectConnection, wireOrBusSelection && EE_CONDITIONS::Idle, 200 ); - menu.AddItem( EE_ACTIONS::addJunction, wireOrBusSelection && EE_CONDITIONS::Idle, 200 ); - menu.AddItem( EE_ACTIONS::addLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 200 ); - menu.AddItem( EE_ACTIONS::addGlobalLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 200 ); - menu.AddItem( EE_ACTIONS::addHierLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 200 ); - menu.AddItem( EE_ACTIONS::breakWire, wireSelection && EE_CONDITIONS::Idle, 200 ); - menu.AddItem( EE_ACTIONS::breakBus, busSelection && EE_CONDITIONS::Idle, 200 ); - menu.AddItem( EE_ACTIONS::importSheetPin, sheetSelection && EE_CONDITIONS::Idle, 200 ); + menu.AddItem( EE_ACTIONS::selectConnection, wireOrBusSelection && EE_CONDITIONS::Idle, 250 ); + menu.AddItem( EE_ACTIONS::addJunction, wireOrBusSelection && EE_CONDITIONS::Idle, 250 ); + menu.AddItem( EE_ACTIONS::addLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 ); + menu.AddItem( EE_ACTIONS::addGlobalLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 ); + menu.AddItem( EE_ACTIONS::addHierLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 ); + menu.AddItem( EE_ACTIONS::breakWire, wireSelection && EE_CONDITIONS::Idle, 250 ); + menu.AddItem( EE_ACTIONS::breakBus, busSelection && EE_CONDITIONS::Idle, 250 ); + menu.AddItem( EE_ACTIONS::addSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 ); + menu.AddItem( EE_ACTIONS::addImportedSheetPin,sheetSelection && EE_CONDITIONS::Idle, 250 ); menu.AddSeparator( havePartCondition && EE_CONDITIONS::Empty, 400 ); menu.AddItem( EE_ACTIONS::symbolProperties, havePartCondition && EE_CONDITIONS::Empty, 400 ); diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index e318c24131..e5b7d86863 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -135,6 +136,14 @@ TOOL_ACTION EE_ACTIONS::addHierLabel( "eeschema.InteractiveEditing.addHierLabel" AS_GLOBAL, 0, _( "Add Hierarchical Label" ), _( "Add a hierarchical label to a wire or bus" ), add_hierarchical_label_xpm, AF_NONE ); +TOOL_ACTION EE_ACTIONS::addSheetPin( "eeschema.InteractiveEditing.addSheetPin", + AS_GLOBAL, 0, _( "Add Sheet Pin" ), _( "Add a sheet pin to the selected sheet" ), + add_hierarchical_label_xpm, AF_NONE ); + +TOOL_ACTION EE_ACTIONS::addImportedSheetPin( "eeschema.InteractiveEditing.addImportedSheetPin", + AS_GLOBAL, 0, _( "Add Imported Sheet Pin" ), _( "Add an imported sheet pin" ), + add_hierarchical_label_xpm, AF_NONE ); + SCH_DRAWING_TOOLS::SCH_DRAWING_TOOLS() : EE_TOOL_BASE( "eeschema.InteractiveDrawing" ) @@ -164,10 +173,21 @@ bool SCH_DRAWING_TOOLS::Init() int SCH_DRAWING_TOOLS::AddJunction( const TOOL_EVENT& aEvent ) { + SELECTION& selection = m_selectionTool->GetSelection(); + SCH_LINE* wire = dynamic_cast( selection.Front() ); + m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); + if( wire ) + { + SEG seg( wire->GetStartPoint(), wire->GetEndPoint() ); + VECTOR2I nearest = seg.NearestPoint( m_frame->GetCrossHairPosition() ); + m_frame->SetCrossHairPosition( (wxPoint) nearest, false ); + } + m_frame->GetCanvas()->MoveCursorToCrossHair(); - m_frame->AddJunction( m_frame->GetCrossHairPosition() ); + SCH_JUNCTION* junction = m_frame->AddJunction( m_frame->GetCrossHairPosition() ); + m_selectionTool->AddItemToSel( junction ); return 0; } @@ -188,6 +208,42 @@ int SCH_DRAWING_TOOLS::AddLabel( const TOOL_EVENT& aEvent ) SCH_ITEM* item = m_frame->CreateNewText( layer ); m_frame->AddItemToScreenAndUndoList( item ); + m_selectionTool->AddItemToSel( item ); + + return 0; +} + + +int SCH_DRAWING_TOOLS::AddSheetPin( const TOOL_EVENT& aEvent ) +{ + SELECTION& selection = m_selectionTool->GetSelection(); + SCH_SHEET* sheet = dynamic_cast( selection.Front() ); + SCH_HIERLABEL* label = nullptr; + + if( !sheet ) + return 0; + + m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); + + if( aEvent.IsAction( &EE_ACTIONS::addImportedSheetPin ) ) + { + label = m_frame->ImportHierLabel( sheet ); + + if( !label ) + { + m_statusPopup.reset( new STATUS_TEXT_POPUP( m_frame ) ); + m_statusPopup->SetTextColor( wxColour( 255, 0, 0 ) ); + m_statusPopup->SetText( _( "No new hierarchical labels found." ) ); + m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); + m_statusPopup->Popup(); + m_statusPopup->Expire( 2000 ); + return 0; + } + } + + SCH_SHEET_PIN* pin = m_frame->CreateSheetPin( sheet, label ); + m_frame->AddItemToScreenAndUndoList( pin ); + m_selectionTool->AddItemToSel( pin ); return 0; } @@ -885,4 +941,6 @@ void SCH_DRAWING_TOOLS::setTransitions() Go( &SCH_DRAWING_TOOLS::AddLabel, EE_ACTIONS::addLabel.MakeEvent() ); Go( &SCH_DRAWING_TOOLS::AddLabel, EE_ACTIONS::addGlobalLabel.MakeEvent() ); Go( &SCH_DRAWING_TOOLS::AddLabel, EE_ACTIONS::addHierLabel.MakeEvent() ); + Go( &SCH_DRAWING_TOOLS::AddSheetPin, EE_ACTIONS::addSheetPin.MakeEvent() ); + Go( &SCH_DRAWING_TOOLS::AddSheetPin, EE_ACTIONS::addImportedSheetPin.MakeEvent() ); } diff --git a/eeschema/tools/sch_drawing_tools.h b/eeschema/tools/sch_drawing_tools.h index 7023113de1..856f7b12db 100644 --- a/eeschema/tools/sch_drawing_tools.h +++ b/eeschema/tools/sch_drawing_tools.h @@ -53,6 +53,7 @@ public: int AddJunction( const TOOL_EVENT& aEvent ); int AddLabel( const TOOL_EVENT& aEvent ); + int AddSheetPin( const TOOL_EVENT& aEvent ); int PlaceSymbol( const TOOL_EVENT& aEvent ); int PlacePower( const TOOL_EVENT& aEvent ); diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 9077a185aa..8b0d57e24c 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -388,7 +388,6 @@ bool SCH_EDIT_TOOL::Init() // CONDITIONAL_MENU& drawMenu = drawingTools->GetToolMenu().GetMenu(); - drawMenu.AddSeparator( EE_CONDITIONS::NotEmpty, 200 ); drawMenu.AddItem( EE_ACTIONS::rotateCCW, orientCondition, 200 ); drawMenu.AddItem( EE_ACTIONS::rotateCW, orientCondition, 200 ); drawMenu.AddItem( EE_ACTIONS::mirrorX, orientCondition, 200 ); @@ -414,7 +413,7 @@ bool SCH_EDIT_TOOL::Init() drawMenu.AddItem( EE_ACTIONS::toHLabel, anyTextTool && EE_CONDITIONS::Idle, 200 ); drawMenu.AddItem( EE_ACTIONS::toGLabel, anyTextTool && EE_CONDITIONS::Idle, 200 ); drawMenu.AddItem( EE_ACTIONS::toText, anyTextTool && EE_CONDITIONS::Idle, 200 ); - drawMenu.AddItem( EE_ACTIONS::cleanupSheetPins, sheetTool && EE_CONDITIONS::Idle, 200 ); + drawMenu.AddItem( EE_ACTIONS::cleanupSheetPins, sheetTool && EE_CONDITIONS::Idle, 250 ); // // Add editing actions to the selection tool menu @@ -449,12 +448,12 @@ bool SCH_EDIT_TOOL::Init() selToolMenu.AddItem( EE_ACTIONS::toHLabel, toHLabelCondition, 200 ); selToolMenu.AddItem( EE_ACTIONS::toGLabel, toGLabelCondition, 200 ); selToolMenu.AddItem( EE_ACTIONS::toText, toTextlCondition, 200 ); - selToolMenu.AddItem( EE_ACTIONS::cleanupSheetPins, singleSheetCondition, 200 ); + selToolMenu.AddItem( EE_ACTIONS::cleanupSheetPins, singleSheetCondition, 250 ); - selToolMenu.AddSeparator( EE_CONDITIONS::Idle, 200 ); - selToolMenu.AddItem( ACTIONS::cut, EE_CONDITIONS::IdleSelection, 200 ); - selToolMenu.AddItem( ACTIONS::copy, EE_CONDITIONS::IdleSelection, 200 ); - selToolMenu.AddItem( ACTIONS::paste, EE_CONDITIONS::Idle, 200 ); + selToolMenu.AddSeparator( EE_CONDITIONS::Idle, 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 ); return true; }