From ceed9ca5f8eafe6d743bc4e223f705c377673cab Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 8 Sep 2025 16:38:49 -0700 Subject: [PATCH] ADDED: Place missing units Adds a contextual menu for symbols that will look for units that are not currently instantiated and offer to place them --- eeschema/eeschema_id.h | 4 ++++ eeschema/tools/sch_actions.cpp | 4 ++-- eeschema/tools/sch_actions.h | 8 ++++++++ eeschema/tools/sch_drawing_tools.cpp | 24 +++++++++++++++++++++--- eeschema/tools/sch_edit_tool.cpp | 9 +++++++-- eeschema/tools/sch_selection_tool.cpp | 10 ++++++++++ 6 files changed, 52 insertions(+), 7 deletions(-) diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index 08f445469c..cf29a845be 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -92,6 +92,10 @@ enum id_eeschema_frm // to select one unit among MAX_UNIT_COUNT_PER_PACKAGE in popup menu ID_POPUP_SCH_SELECT_UNIT_END = ID_POPUP_SCH_SELECT_UNIT1 + MAX_UNIT_COUNT_PER_PACKAGE, + ID_POPUP_SCH_PLACE_UNIT, + ID_POPUP_SCH_PLACE_UNIT1, + ID_POPUP_SCH_PLACE_UNIT_END = ID_POPUP_SCH_PLACE_UNIT1 + MAX_UNIT_COUNT_PER_PACKAGE, + ID_POPUP_SCH_SELECT_BODY_STYLE, ID_POPUP_SCH_SELECT_BODY_STYLE1, ID_POPUP_SCH_SELECT_BODY_STYLE_END = ID_POPUP_SCH_SELECT_BODY_STYLE1 + MAX_BODY_STYLE_PER_PACKAGE, diff --git a/eeschema/tools/sch_actions.cpp b/eeschema/tools/sch_actions.cpp index 682e42b0c9..4e859a4e6a 100644 --- a/eeschema/tools/sch_actions.cpp +++ b/eeschema/tools/sch_actions.cpp @@ -438,8 +438,8 @@ TOOL_ACTION SCH_ACTIONS::placeNextSymbolUnit( TOOL_ACTION_ARGS() .FriendlyName( _( "Place Next Symbol Unit" ) ) .Tooltip( _( "Place the next unit of the current symbol that is missing from the schematic" ) ) .Flags( AF_ACTIVATE ) - // The symbol to use as a reference for the next unit - .Parameter( nullptr ) ); + // The symbol to use as a reference for the next unit and optionally the unit number + .Parameter( {} ) ); TOOL_ACTION SCH_ACTIONS::placePower( TOOL_ACTION_ARGS() .Name( "eeschema.InteractiveDrawing.placePowerSymbol" ) diff --git a/eeschema/tools/sch_actions.h b/eeschema/tools/sch_actions.h index b04f79eea2..6bf2e1f5c4 100644 --- a/eeschema/tools/sch_actions.h +++ b/eeschema/tools/sch_actions.h @@ -310,4 +310,12 @@ public: ///< If a symbol is provide, reannotate it? bool m_Reannotate = true; }; + + struct PLACE_SYMBOL_UNIT_PARAMS + { + ///< Symbol used as reference for unit placement + SCH_SYMBOL* m_Symbol = nullptr; + ///< Unit number to place; 0 means next available unit + int m_Unit = 0; + }; }; diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index a25f040a60..d64d32146e 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -619,7 +619,10 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) int SCH_DRAWING_TOOLS::PlaceNextSymbolUnit( const TOOL_EVENT& aEvent ) { - SCH_SYMBOL* symbol = aEvent.Parameter(); + const SCH_ACTIONS::PLACE_SYMBOL_UNIT_PARAMS& params = + aEvent.Parameter(); + SCH_SYMBOL* symbol = params.m_Symbol; + int requestedUnit = params.m_Unit; // TODO: get from selection if( !symbol ) @@ -654,8 +657,23 @@ int SCH_DRAWING_TOOLS::PlaceNextSymbolUnit( const TOOL_EVENT& aEvent ) return 0; } - // Find the lowest unit number that is missing - const int nextMissing = *std::min_element( missingUnits.begin(), missingUnits.end() ); + int nextMissing; + + if( requestedUnit > 0 ) + { + if( missingUnits.count( requestedUnit ) == 0 ) + { + m_frame->ShowInfoBarMsg( _( "Requested unit already placed." ) ); + return 0; + } + + nextMissing = requestedUnit; + } + else + { + // Find the lowest unit number that is missing + nextMissing = *std::min_element( missingUnits.begin(), missingUnits.end() ); + } std::unique_ptr newSymbol = std::make_unique( *symbol ); const SCH_SHEET_PATH& sheetPath = m_frame->GetCurrentSheet(); diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 42c2786aff..ebb9c40411 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -121,11 +121,16 @@ private: break; // We have used all IDs for these submenus } + if( !missingUnits.empty() ) { AppendSeparator(); - wxMenuItem* item = Add( SCH_ACTIONS::placeNextSymbolUnit ); - item->Enable( missingUnits.size() ); + for( int unitNumber : missingUnits ) + { + wxString placeText = wxString::Format( _( "Place unit %s" ), + symbol->GetUnitDisplayName( unitNumber, false ) ); + Append( ID_POPUP_SCH_PLACE_UNIT1 + unitNumber - 1, placeText ); + } } } }; diff --git a/eeschema/tools/sch_selection_tool.cpp b/eeschema/tools/sch_selection_tool.cpp index cbf5f7ff2e..5cbf5ece33 100644 --- a/eeschema/tools/sch_selection_tool.cpp +++ b/eeschema/tools/sch_selection_tool.cpp @@ -787,6 +787,16 @@ int SCH_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) if( symbol ) static_cast( m_frame )->SelectUnit( symbol, unit ); } + else if( *evt->GetCommandId() >= ID_POPUP_SCH_PLACE_UNIT + && *evt->GetCommandId() <= ID_POPUP_SCH_PLACE_UNIT_END ) + { + SCH_SYMBOL* symbol = dynamic_cast( m_selection.Front() ); + int unit = *evt->GetCommandId() - ID_POPUP_SCH_PLACE_UNIT; + + if( symbol ) + m_toolMgr->RunAction( SCH_ACTIONS::placeNextSymbolUnit, + SCH_ACTIONS::PLACE_SYMBOL_UNIT_PARAMS{ symbol, unit } ); + } else if( *evt->GetCommandId() >= ID_POPUP_SCH_SELECT_BODY_STYLE && *evt->GetCommandId() <= ID_POPUP_SCH_SELECT_BODY_STYLE_END ) {