From 49a8c9eb8d47ced9378edb78b590155375286c5d Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Thu, 28 Sep 2023 15:06:31 -0400 Subject: [PATCH] Schematic: pin helpers, add wiring tool --- eeschema/eeschema_id.h | 1 + eeschema/tools/ee_selection_tool.cpp | 49 +++++++++++++++++++++++++++- eeschema/tools/sch_edit_tool.cpp | 1 + 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index f8308dc9b6..3ee22336a2 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -88,6 +88,7 @@ enum id_eeschema_frm ID_POPUP_SCH_PIN_TRICKS_START, ID_POPUP_SCH_PIN_TRICKS_NO_CONNECT = ID_POPUP_SCH_PIN_TRICKS_START, + ID_POPUP_SCH_PIN_TRICKS_WIRE, ID_POPUP_SCH_PIN_TRICKS_NET_LABEL, ID_POPUP_SCH_PIN_TRICKS_HIER_LABEL, ID_POPUP_SCH_PIN_TRICKS_GLOBAL_LABEL, diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index bba12ac826..1c5e0022fa 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -618,7 +618,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) else if( *evt->GetCommandId() >= ID_POPUP_SCH_PIN_TRICKS_START && *evt->GetCommandId() <= ID_POPUP_SCH_PIN_TRICKS_END ) { - if( !m_selection.OnlyContains( { SCH_PIN_T } ) ) + if( !m_selection.OnlyContains( { SCH_PIN_T } ) || m_selection.Empty() ) return 0; // Keep track of new items so we make them the new selection at the end @@ -638,6 +638,53 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) commit.Push( wxS( "No Connect Pins" ) ); ClearSelection(); } + else if( *evt->GetCommandId() == ID_POPUP_SCH_PIN_TRICKS_WIRE ) + { + VECTOR2I wireGrid = grid.GetGridSize( GRID_HELPER_GRIDS::GRID_WIRES ); + + for( EDA_ITEM* item : m_selection ) + { + SCH_PIN* pin = static_cast( item ); + SCH_LINE* wire = new SCH_LINE( pin->GetPosition(), LAYER_WIRE ); + + // Add some length to the wire as nothing in our code base handles + // 0 length wires very well, least of all the ortho drag algorithm + VECTOR2I stub; + + switch( pin->GetOrientation() ) + { + case PIN_ORIENTATION::PIN_LEFT: stub = VECTOR2I( 1 * wireGrid.x, 0 ); break; + case PIN_ORIENTATION::PIN_RIGHT: stub = VECTOR2I( -1 * wireGrid.x, 0 ); break; + case PIN_ORIENTATION::PIN_UP: stub = VECTOR2I( 0, 1 * wireGrid.y ); break; + case PIN_ORIENTATION::PIN_DOWN: stub = VECTOR2I( 0, -1 * wireGrid.y ); break; + } + + wire->SetEndPoint( pin->GetPosition() + stub ); + + m_frame->AddToScreen( wire, m_frame->GetScreen() ); + commit.Added( wire, m_frame->GetScreen() ); + newItems.push_back( wire ); + } + + ClearSelection(); + AddItemsToSel( &newItems ); + + // Select only the ends so we can immediately start dragging them + for( EDA_ITEM* item : newItems ) + static_cast( item )->SetFlags( ENDPOINT ); + + // Put the mouse on the nearest point of the first wire + SCH_LINE* first = static_cast( newItems[0] ); + getViewControls()->SetCrossHairCursorPosition( first->GetEndPoint(), false ); + getViewControls()->WarpMouseCursor( getViewControls()->GetCursorPosition(), + true ); + + // Start the drag tool, canceling will remove the wires + if( m_toolMgr->RunSynchronousAction( EE_ACTIONS::drag, &commit, false ) ) + commit.Push( wxS( "Wire Pins" ) ); + else + commit.Revert(); + } else { // For every pin in the selection, add a label according to menu item diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index c5b053183e..5c342e9bdc 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -215,6 +215,7 @@ private: if( !pin ) return; + Add( wxS( "Wire" ), ID_POPUP_SCH_PIN_TRICKS_WIRE, BITMAPS::add_line ); Add( wxS( "No Connect" ), ID_POPUP_SCH_PIN_TRICKS_NO_CONNECT, BITMAPS::noconn ); Add( wxS( "Net Label" ), ID_POPUP_SCH_PIN_TRICKS_NET_LABEL, BITMAPS::add_label ); Add( wxS( "Hierarchical Label" ), ID_POPUP_SCH_PIN_TRICKS_HIER_LABEL,