mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-13 17:53:11 +02:00
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
This commit is contained in:
parent
6c4edd178e
commit
ceed9ca5f8
@ -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,
|
||||
|
@ -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<SCH_SYMBOL*>( nullptr ) );
|
||||
// The symbol to use as a reference for the next unit and optionally the unit number
|
||||
.Parameter<SCH_ACTIONS::PLACE_SYMBOL_UNIT_PARAMS>( {} ) );
|
||||
|
||||
TOOL_ACTION SCH_ACTIONS::placePower( TOOL_ACTION_ARGS()
|
||||
.Name( "eeschema.InteractiveDrawing.placePowerSymbol" )
|
||||
|
@ -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;
|
||||
};
|
||||
};
|
||||
|
@ -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<SCH_SYMBOL*>();
|
||||
const SCH_ACTIONS::PLACE_SYMBOL_UNIT_PARAMS& params =
|
||||
aEvent.Parameter<SCH_ACTIONS::PLACE_SYMBOL_UNIT_PARAMS>();
|
||||
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<SCH_SYMBOL> newSymbol = std::make_unique<SCH_SYMBOL>( *symbol );
|
||||
const SCH_SHEET_PATH& sheetPath = m_frame->GetCurrentSheet();
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -787,6 +787,16 @@ int SCH_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||
if( symbol )
|
||||
static_cast<SCH_EDIT_FRAME*>( 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<SCH_SYMBOL*>( 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 )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user