From ac1f7f93a2e4e5e3939db4b68f551673721b58d3 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 27 Dec 2020 13:07:16 -0500 Subject: [PATCH] Save context menu position for bus unfold Fixes https://gitlab.com/kicad/code/kicad/-/issues/6378 --- eeschema/tools/sch_line_wire_bus_tool.cpp | 15 ++++++++++----- eeschema/tools/sch_line_wire_bus_tool.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index 324d231836..d9f8b0e6c4 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -359,14 +359,16 @@ int SCH_LINE_WIRE_BUS_TOOL::UnfoldBus( const TOOL_EVENT& aEvent ) } -SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus( const wxString& aNet ) +SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus( const wxString& aNet, wxPoint aPos ) { SCHEMATIC_SETTINGS& cfg = getModel()->Settings(); - wxPoint pos = (wxPoint) getViewControls()->GetCursorPosition(); + + if( aPos == wxDefaultPosition ) + aPos = static_cast( getViewControls()->GetCursorPosition() ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); - m_busUnfold.entry = new SCH_BUS_WIRE_ENTRY( pos ); + m_busUnfold.entry = new SCH_BUS_WIRE_ENTRY( aPos ); m_busUnfold.entry->SetParent( m_frame->GetScreen() ); m_frame->AddToScreen( m_busUnfold.entry, m_frame->GetScreen() ); @@ -377,7 +379,7 @@ SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus( const wxString& aNet ) m_busUnfold.label->SetFlags( IS_NEW | IS_MOVED ); m_busUnfold.in_progress = true; - m_busUnfold.origin = pos; + m_busUnfold.origin = aPos; m_busUnfold.net_name = aNet; getViewControls()->SetCrossHairCursorPosition( m_busUnfold.entry->GetEnd(), false ); @@ -499,6 +501,8 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType, // Set initial cursor setCursor(); + wxPoint contextMenuPos; + // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) { @@ -723,6 +727,7 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType, if( !segment ) m_toolMgr->VetoContextMenuMouseWarp(); + contextMenuPos = cursorPos; m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); } else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CHOICE_MENU_CHOICE ) @@ -734,7 +739,7 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType, aType = LAYER_WIRE; wxString net = *evt->Parameter(); - segment = doUnfoldBus( net ); + segment = doUnfoldBus( net, contextMenuPos ); } } else diff --git a/eeschema/tools/sch_line_wire_bus_tool.h b/eeschema/tools/sch_line_wire_bus_tool.h index 98090f3c86..affc364431 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.h +++ b/eeschema/tools/sch_line_wire_bus_tool.h @@ -98,7 +98,7 @@ public: private: int doDrawSegments( const std::string& aTool, int aType, bool aQuitOnDraw ); SCH_LINE* startSegments( int aType, const VECTOR2D& aPos ); - SCH_LINE* doUnfoldBus( const wxString& aNet ); + SCH_LINE* doUnfoldBus( const wxString& aNet, wxPoint aPos = wxDefaultPosition ); void finishSegments(); /**