diff --git a/eeschema/tools/ee_actions.cpp b/eeschema/tools/ee_actions.cpp index 1a284c944a..bcae56f09e 100644 --- a/eeschema/tools/ee_actions.cpp +++ b/eeschema/tools/ee_actions.cpp @@ -336,11 +336,6 @@ TOOL_ACTION EE_ACTIONS::drawSheet( "eeschema.InteractiveDrawing.drawSheet", _( "Add Sheet" ), _( "Add a hierarchical sheet" ), BITMAPS::add_hierarchical_subsheet, AF_ACTIVATE, (void*) SCH_SHEET_T ); -TOOL_ACTION EE_ACTIONS::importSingleSheetPin( "eeschema.InteractiveDrawing.importSingleSheetPin", - AS_GLOBAL, 0, "", - _( "Import Sheet Pin" ), _( "Import a hierarchical sheet pin" ), - BITMAPS::add_hierar_pin, AF_ACTIVATE, (void*) SCH_SHEET_PIN_T ); - TOOL_ACTION EE_ACTIONS::importSheetPin( "eeschema.InteractiveDrawing.importSheetPin", AS_GLOBAL, 0, "", _( "Import Sheet Pin" ), _( "Import a hierarchical sheet pin" ), diff --git a/eeschema/tools/ee_actions.h b/eeschema/tools/ee_actions.h index ecfbf40e33..92cd2ce135 100644 --- a/eeschema/tools/ee_actions.h +++ b/eeschema/tools/ee_actions.h @@ -91,7 +91,6 @@ public: static TOOL_ACTION placeGlobalLabel; static TOOL_ACTION placeHierLabel; static TOOL_ACTION drawSheet; - static TOOL_ACTION importSingleSheetPin; static TOOL_ACTION importSheetPin; static TOOL_ACTION placeSchematicText; static TOOL_ACTION drawTextBox; diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 5329c17385..a354c0259e 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -274,7 +274,7 @@ bool EE_SELECTION_TOOL::Init() menu.AddItem( EE_ACTIONS::placeHierLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 ); menu.AddItem( EE_ACTIONS::breakWire, linesSelection && EE_CONDITIONS::Idle, 250 ); menu.AddItem( EE_ACTIONS::slice, linesSelection && EE_CONDITIONS::Idle, 250 ); - menu.AddItem( EE_ACTIONS::importSingleSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 ); + menu.AddItem( EE_ACTIONS::importSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 ); menu.AddItem( EE_ACTIONS::assignNetclass, connectedSelection && EE_CONDITIONS::Idle, 250 ); menu.AddItem( EE_ACTIONS::editPageNumber, schEditSheetPageNumberCondition, 250 ); diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 5cd8c2fb51..e06226cc78 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -729,29 +729,6 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) previewItem->SetParent( m_frame->GetScreen() ); break; - case SCH_SHEET_PIN_T: - { - EE_SELECTION& selection = m_selectionTool->GetSelection(); - SCH_SHEET* sheet = dynamic_cast( selection.Front() ); - - if( !sheet ) - return 0; - - SCH_HIERLABEL* label = importHierLabel( sheet ); - - if( !label ) - { - m_statusPopup = std::make_unique( m_frame ); - m_statusPopup->SetText( _( "No new hierarchical labels found." ) ); - m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); - m_statusPopup->PopupFor( 2000 ); - return 0; - } - - previewItem = createSheetPin( sheet, label, cursorPos ); - } - break; - default: wxASSERT_MSG( false, "Unknown item type in SCH_DRAWING_TOOLS::SingleClickPlace" ); return 0; @@ -1130,6 +1107,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) EE_GRID_HELPER grid( m_toolMgr ); bool ignorePrimePosition = false; COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings(); + SCH_SHEET* sheet = nullptr; if( m_inTwoClickPlace ) return 0; @@ -1144,9 +1122,14 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) bool isSheetPin = aEvent.IsAction( &EE_ACTIONS::importSheetPin ); int snapLayer = isText ? LAYER_GRAPHICS : LAYER_CONNECTABLE; + // If we have a selected sheet use it, otherwise try to get one under the cursor + if( isSheetPin ) + sheet = dynamic_cast( m_selectionTool->GetSelection().Front() ); + m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_frame->PushTool( aEvent ); + auto setCursor = [&]() { @@ -1221,6 +1204,33 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent ); + auto createNextSheetPin = + [&]() + { + if( !sheet ) + return; + + SCH_HIERLABEL* label = importHierLabel( sheet ); + + if( !label ) + { + m_statusPopup = std::make_unique( m_frame ); + m_statusPopup->SetText( _( "No new hierarchical labels found." ) ); + m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); + m_statusPopup->PopupFor( 2000 ); + item = nullptr; + } + else + { + item = createSheetPin( sheet, label, cursorPos ); + + if( item->Type() == SCH_SHEET_PIN_T ) + { + item->ClearSelected(); + } + } + }; + if( evt->IsCancelInteractive() ) { m_frame->GetInfoBar()->Dismiss(); @@ -1345,15 +1355,12 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) } else if( isSheetPin ) { - EDA_ITEM* i; - SCH_HIERLABEL* label = nullptr; - SCH_SHEET* sheet = nullptr; + EDA_ITEM* i; - if( m_selectionTool->SelectPoint( cursorPos, { SCH_SHEET_T }, &i ) ) + // If we didn't have a sheet selected, try to find one under the cursor + if( !sheet && m_selectionTool->SelectPoint( cursorPos, { SCH_SHEET_T }, &i ) ) sheet = dynamic_cast( i ); - m_selectionTool->ClearSelection(); - if( !sheet ) { m_statusPopup = std::make_unique( m_frame ); @@ -1364,24 +1371,12 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) } else { - label = importHierLabel( sheet ); + createNextSheetPin(); - if( !label ) + if( !item ) { - m_statusPopup = std::make_unique( m_frame ); - m_statusPopup->SetText( _( "No new hierarchical labels found." ) ); - m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); - m_statusPopup->PopupFor( 2000 ); - item = nullptr; - } - else - { - item = createSheetPin( sheet, label, cursorPos ); - - if( item->Type() == SCH_SHEET_PIN_T ) - { - item->ClearSelected(); - } + m_frame->PopTool( aEvent ); + break; } } } @@ -1426,6 +1421,18 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) item = nullptr; m_view->ClearPreview(); + + // Exit the tool when this sheet runs out of pins for convenience + if( isSheetPin ) + { + createNextSheetPin(); + + if( !item ) + { + m_frame->PopTool( aEvent ); + break; + } + } } } else if( evt->IsClick( BUT_RIGHT ) ) @@ -1909,7 +1916,6 @@ void SCH_DRAWING_TOOLS::setTransitions() Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeGlobalLabel.MakeEvent() ); Go( &SCH_DRAWING_TOOLS::DrawSheet, EE_ACTIONS::drawSheet.MakeEvent() ); Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::importSheetPin.MakeEvent() ); - Go( &SCH_DRAWING_TOOLS::SingleClickPlace, EE_ACTIONS::importSingleSheetPin.MakeEvent() ); Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeSchematicText.MakeEvent() ); Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawRectangle.MakeEvent() ); Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawCircle.MakeEvent() );