mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-19 23:21:41 +00:00
Add 'Increment' actions
These are context sensitive actions that increment "something" about the selected item. A generic 'increment' action can be produced, e.g. by other tools or UI events, which has in increment step (positive or negative) and an 'index' which determines what about the item should be incremented - it's up to the increment action handler to decide what that means. And then add a primary and secondary inc/decrement action, which allows to bind hotkeys to each. Bind these to: * Sym edit: increment pin names/number increment text items * Sch edit: increment lables and text * FP/PCB: increment pin numbers increment text items
This commit is contained in:
parent
f77d830d79
commit
3f602f8177
common/tool
eeschema/tools
ee_actions.cppee_actions.hsch_edit_tool.cppsch_edit_tool.hsymbol_editor_edit_tool.cppsymbol_editor_edit_tool.h
include/tool
pcbnew/tools
@ -333,6 +333,42 @@ TOOL_ACTION ACTIONS::collapseAll( TOOL_ACTION_ARGS()
|
||||
.FriendlyName( _( "Collapse All" ) )
|
||||
.Icon( BITMAPS::down ) ); // JEY TODO: need icon
|
||||
|
||||
// This is the generic increment action, and will need the parameter
|
||||
// to be filled in by the event producer.
|
||||
TOOL_ACTION ACTIONS::increment( TOOL_ACTION_ARGS()
|
||||
.Name( "eeschema.Interactive.increment" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Increment" ) )
|
||||
.Tooltip( _( "Increment the selected item(s)" ) ) );
|
||||
|
||||
TOOL_ACTION ACTIONS::incrementPrimary( TOOL_ACTION_ARGS()
|
||||
.Name( "eeschema.Interactive.incrementPrimary" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Increment Primary" ) )
|
||||
.Tooltip( _( "Increment the primary field of the selected item(s)" ) )
|
||||
.Parameter( ACTIONS::INCREMENT{ 1, 0 } ) );
|
||||
|
||||
TOOL_ACTION ACTIONS::decrementPrimary( TOOL_ACTION_ARGS()
|
||||
.Name( "eeschema.Interactive.decrementPrimary" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Decrement Primary" ) )
|
||||
.Tooltip( _( "Decrement the primary field of the selected item(s)" ) )
|
||||
.Parameter( ACTIONS::INCREMENT{ -1, 0 } ) );
|
||||
|
||||
TOOL_ACTION ACTIONS::incrementSecondary( TOOL_ACTION_ARGS()
|
||||
.Name( "eeschema.Interactive.incrementSecondary" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Increment Secondary" ) )
|
||||
.Tooltip( _( "Increment the secondary field of the selected item(s)" ) )
|
||||
.Parameter( ACTIONS::INCREMENT{ 1, 1 } ) );
|
||||
|
||||
TOOL_ACTION ACTIONS::decrementSecondary( TOOL_ACTION_ARGS()
|
||||
.Name( "eeschema.Interactive.decrementSecondary" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Decrement Secondary" ) )
|
||||
.Tooltip( _( "Decrement the secondary field of the selected item(s)" ) )
|
||||
.Parameter( ACTIONS::INCREMENT{ -1, 1 } ) );
|
||||
|
||||
TOOL_ACTION ACTIONS::selectColumns( TOOL_ACTION_ARGS()
|
||||
.Name( "common.InteractiveSelection.SelectColumns" )
|
||||
.Scope( AS_GLOBAL )
|
||||
|
@ -90,7 +90,6 @@ TOOL_ACTION EE_ACTIONS::pointEditorRemoveCorner( TOOL_ACTION_ARGS()
|
||||
.FriendlyName( _( "Remove Corner" ) )
|
||||
.Icon( BITMAPS::delete_cursor ) );
|
||||
|
||||
|
||||
// EE_SELECTION_TOOL
|
||||
//
|
||||
TOOL_ACTION EE_ACTIONS::selectionActivate( TOOL_ACTION_ARGS()
|
||||
|
@ -311,4 +311,10 @@ public:
|
||||
|
||||
// Drag and drop
|
||||
static TOOL_ACTION ddAppendFile;
|
||||
|
||||
enum PIN_INCREMENT
|
||||
{
|
||||
NUMBER = 0,
|
||||
NAME,
|
||||
};
|
||||
};
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <tools/sch_drawing_tools.h>
|
||||
#include <ee_actions.h>
|
||||
#include <confirm.h>
|
||||
#include <increment.h>
|
||||
#include <string_utils.h>
|
||||
#include <sch_bitmap.h>
|
||||
#include <sch_bus_entry.h>
|
||||
@ -2957,6 +2958,68 @@ int SCH_EDIT_TOOL::EditPageNumber( const TOOL_EVENT& aEvent )
|
||||
}
|
||||
|
||||
|
||||
int SCH_EDIT_TOOL::Increment( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
const ACTIONS::INCREMENT incParam = aEvent.Parameter<ACTIONS::INCREMENT>();
|
||||
static const std::vector<KICAD_T> incrementable = { SCH_LABEL_T, SCH_GLOBAL_LABEL_T,
|
||||
SCH_HIER_LABEL_T, SCH_TEXT_T };
|
||||
EE_SELECTION& selection = m_selectionTool->RequestSelection( incrementable );
|
||||
|
||||
if( selection.Empty() )
|
||||
return 0;
|
||||
|
||||
KICAD_T type = selection.Front()->Type();
|
||||
bool allSameType = true;
|
||||
for( EDA_ITEM* item : selection )
|
||||
{
|
||||
if( item->Type() != type )
|
||||
{
|
||||
allSameType = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Incrementing multiple types at once seems confusing
|
||||
// though it would work.
|
||||
if( !allSameType )
|
||||
return 0;
|
||||
|
||||
SCH_COMMIT commit( m_frame );
|
||||
|
||||
for( EDA_ITEM* item : selection )
|
||||
{
|
||||
switch( item->Type() )
|
||||
{
|
||||
case SCH_LABEL_T:
|
||||
case SCH_GLOBAL_LABEL_T:
|
||||
case SCH_HIER_LABEL_T:
|
||||
case SCH_TEXT_T:
|
||||
{
|
||||
// Only support the first index for now
|
||||
if( incParam.Index == 0 )
|
||||
{
|
||||
SCH_TEXT& label = static_cast<SCH_TEXT&>( *item );
|
||||
|
||||
wxString nextLabel = label.GetText();
|
||||
IncrementString( nextLabel, incParam.Delta );
|
||||
|
||||
commit.Modify( &label, m_frame->GetScreen() );
|
||||
label.SetText( nextLabel );
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// No increment for other items (yet)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
commit.Push( _( "Increment" ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int SCH_EDIT_TOOL::DdAppendFile( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
return m_toolMgr->RunAction( EE_ACTIONS::importSheet, aEvent.Parameter<wxString*>() );
|
||||
@ -3077,6 +3140,7 @@ int SCH_EDIT_TOOL::ToggleAttribute( const TOOL_EVENT& aEvent )
|
||||
|
||||
void SCH_EDIT_TOOL::setTransitions()
|
||||
{
|
||||
// clang-format off
|
||||
Go( &SCH_EDIT_TOOL::RepeatDrawItem, EE_ACTIONS::repeatDrawItem.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::Rotate, EE_ACTIONS::rotateCW.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::Rotate, EE_ACTIONS::rotateCCW.MakeEvent() );
|
||||
@ -3086,6 +3150,12 @@ void SCH_EDIT_TOOL::setTransitions()
|
||||
Go( &SCH_EDIT_TOOL::DoDelete, ACTIONS::doDelete.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::InteractiveDelete, ACTIONS::deleteTool.MakeEvent() );
|
||||
|
||||
Go( &SCH_EDIT_TOOL::Increment, ACTIONS::increment.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::Increment, ACTIONS::incrementPrimary.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::Increment, ACTIONS::decrementPrimary.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::Increment, ACTIONS::incrementSecondary.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::Increment, ACTIONS::decrementSecondary.MakeEvent() );
|
||||
|
||||
Go( &SCH_EDIT_TOOL::Properties, EE_ACTIONS::properties.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::EditField, EE_ACTIONS::editReference.MakeEvent() );
|
||||
Go( &SCH_EDIT_TOOL::EditField, EE_ACTIONS::editValue.MakeEvent() );
|
||||
@ -3129,4 +3199,5 @@ void SCH_EDIT_TOOL::setTransitions()
|
||||
Go( &SCH_EDIT_TOOL::EditPageNumber, EE_ACTIONS::editPageNumber.MakeEvent() );
|
||||
|
||||
Go( &SCH_EDIT_TOOL::DdAppendFile, EE_ACTIONS::ddAppendFile.MakeEvent() );
|
||||
// clang-format on
|
||||
}
|
||||
|
@ -57,6 +57,11 @@ public:
|
||||
int ChangeBodyStyle( const TOOL_EVENT& aEvent );
|
||||
int EditPageNumber( const TOOL_EVENT& aEvent );
|
||||
|
||||
/**
|
||||
* Increment/decrement something about an item.
|
||||
*/
|
||||
int Increment( const TOOL_EVENT& aEvent );
|
||||
|
||||
/**
|
||||
* Change a text type to another one.
|
||||
*
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <tools/symbol_editor_move_tool.h>
|
||||
#include <clipboard.h>
|
||||
#include <ee_actions.h>
|
||||
#include <increment.h>
|
||||
#include <string_utils.h>
|
||||
#include <symbol_edit_frame.h>
|
||||
#include <sch_commit.h>
|
||||
@ -1079,6 +1080,93 @@ int SYMBOL_EDITOR_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
||||
}
|
||||
|
||||
|
||||
int SYMBOL_EDITOR_EDIT_TOOL::Increment( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
const ACTIONS::INCREMENT incParam = aEvent.Parameter<ACTIONS::INCREMENT>();
|
||||
EE_SELECTION& selection = m_selectionTool->RequestSelection( { SCH_PIN_T } );
|
||||
|
||||
if( selection.Empty() )
|
||||
return 0;
|
||||
|
||||
KICAD_T type = selection.Front()->Type();
|
||||
bool allSameType = true;
|
||||
for( EDA_ITEM* item : selection )
|
||||
{
|
||||
if( item->Type() != type )
|
||||
{
|
||||
allSameType = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Incrementing multiple types at once seems confusing
|
||||
// though it would work.
|
||||
if( !allSameType )
|
||||
return 0;
|
||||
|
||||
SCH_COMMIT commit( m_frame );
|
||||
|
||||
for( EDA_ITEM* item : selection )
|
||||
{
|
||||
switch( item->Type() )
|
||||
{
|
||||
case SCH_PIN_T:
|
||||
{
|
||||
SCH_PIN& pin = static_cast<SCH_PIN&>( *item );
|
||||
|
||||
// This is is a bit annoying, as it severely limits the number of scroll
|
||||
// actions. It would be better if we could figure out which field the user
|
||||
// wanted to increment from the cursor position. Then we could use the
|
||||
// index to choose, say, to increment different bits of the pin.
|
||||
switch( incParam.Index )
|
||||
{
|
||||
case EE_ACTIONS::PIN_INCREMENT::NUMBER:
|
||||
{
|
||||
wxString nextNumber = pin.GetNumber();
|
||||
IncrementString( nextNumber, incParam.Delta );
|
||||
|
||||
commit.Modify( &pin );
|
||||
pin.SetNumber( nextNumber );
|
||||
break;
|
||||
}
|
||||
case EE_ACTIONS::PIN_INCREMENT::NAME:
|
||||
{
|
||||
wxString nextName = pin.GetName();
|
||||
IncrementString( nextName, incParam.Delta );
|
||||
|
||||
commit.Modify( &pin );
|
||||
pin.SetName( nextName );
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Only handle number and name for now
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SCH_TEXT_T:
|
||||
{
|
||||
SCH_TEXT& text = static_cast<SCH_TEXT&>( *item );
|
||||
|
||||
wxString nextText = text.GetText();
|
||||
IncrementString( nextText, incParam.Delta );
|
||||
|
||||
commit.Modify( &text );
|
||||
text.SetText( nextText );
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// No increment for other items
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
commit.Push( _( "Increment" ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_EDITOR_EDIT_TOOL::setTransitions()
|
||||
{
|
||||
// clang-format off
|
||||
@ -1098,6 +1186,12 @@ void SYMBOL_EDITOR_EDIT_TOOL::setTransitions()
|
||||
Go( &SYMBOL_EDITOR_EDIT_TOOL::DoDelete, ACTIONS::doDelete.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_EDIT_TOOL::InteractiveDelete, ACTIONS::deleteTool.MakeEvent() );
|
||||
|
||||
Go( &SYMBOL_EDITOR_EDIT_TOOL::Increment, ACTIONS::increment.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_EDIT_TOOL::Increment, ACTIONS::incrementPrimary.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_EDIT_TOOL::Increment, ACTIONS::decrementPrimary.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_EDIT_TOOL::Increment, ACTIONS::incrementSecondary.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_EDIT_TOOL::Increment, ACTIONS::decrementSecondary.MakeEvent() );
|
||||
|
||||
Go( &SYMBOL_EDITOR_EDIT_TOOL::Properties, EE_ACTIONS::properties.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_EDIT_TOOL::Properties, EE_ACTIONS::symbolProperties.MakeEvent() );
|
||||
Go( &SYMBOL_EDITOR_EDIT_TOOL::PinTable, EE_ACTIONS::pinTable.MakeEvent() );
|
||||
|
@ -59,6 +59,8 @@ public:
|
||||
int CopyAsText( const TOOL_EVENT& aEvent );
|
||||
int Paste( const TOOL_EVENT& aEvent );
|
||||
|
||||
int Increment( const TOOL_EVENT& aEvent );
|
||||
|
||||
/**
|
||||
* Delete the selected items, or the item under the cursor.
|
||||
*/
|
||||
|
@ -83,6 +83,13 @@ public:
|
||||
static TOOL_ACTION expandAll;
|
||||
static TOOL_ACTION collapseAll;
|
||||
|
||||
// Incrementing
|
||||
static TOOL_ACTION increment;
|
||||
static TOOL_ACTION incrementPrimary;
|
||||
static TOOL_ACTION decrementPrimary;
|
||||
static TOOL_ACTION incrementSecondary;
|
||||
static TOOL_ACTION decrementSecondary;
|
||||
|
||||
// Tables
|
||||
static TOOL_ACTION selectRows;
|
||||
static TOOL_ACTION selectColumns;
|
||||
@ -260,6 +267,16 @@ public:
|
||||
ALT = 0x01,
|
||||
CUT = 0x02
|
||||
};
|
||||
|
||||
///< Increment event parameters
|
||||
struct INCREMENT
|
||||
{
|
||||
// Amount to increment
|
||||
int Delta;
|
||||
// Which "thing" to increment
|
||||
// (what this is depends on the action - a pin might be number, then name)
|
||||
int Index;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <board.h>
|
||||
#include <board_design_settings.h>
|
||||
#include <footprint.h>
|
||||
#include <increment.h>
|
||||
#include <pcb_shape.h>
|
||||
#include <pcb_group.h>
|
||||
#include <pcb_target.h>
|
||||
@ -2961,6 +2962,73 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent )
|
||||
}
|
||||
|
||||
|
||||
int EDIT_TOOL::Increment( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
const auto incrementableFilter =
|
||||
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
|
||||
{
|
||||
for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
|
||||
{
|
||||
if( aCollector[i]->Type() != PCB_PAD_T )
|
||||
aCollector.Remove( i );
|
||||
}
|
||||
};
|
||||
|
||||
PCB_SELECTION& selection = m_selectionTool->RequestSelection(
|
||||
incrementableFilter, true /* prompt user regarding locked items */ );
|
||||
|
||||
if( selection.Empty() )
|
||||
return 0;
|
||||
|
||||
const ACTIONS::INCREMENT incParam = aEvent.Parameter<ACTIONS::INCREMENT>();
|
||||
|
||||
BOARD_COMMIT commit( this );
|
||||
|
||||
for( EDA_ITEM* item : selection )
|
||||
{
|
||||
switch( item->Type() )
|
||||
{
|
||||
case PCB_PAD_T:
|
||||
{
|
||||
PAD& pad = static_cast<PAD&>( *item );
|
||||
|
||||
if( !pad.CanHaveNumber() )
|
||||
continue;
|
||||
|
||||
// Increment only handled for pad numbers
|
||||
if( incParam.Index == PCB_ACTIONS::PAD_INCREMENT::NUMBER )
|
||||
{
|
||||
wxString padNumber = pad.GetNumber();
|
||||
IncrementString( padNumber, incParam.Delta );
|
||||
|
||||
commit.Modify( &pad );
|
||||
pad.SetNumber( padNumber );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PCB_TEXT_T:
|
||||
{
|
||||
PCB_TEXT& text = static_cast<PCB_TEXT&>( *item );
|
||||
|
||||
wxString content = text.GetText();
|
||||
IncrementString( content, incParam.Delta );
|
||||
|
||||
commit.Modify( &text );
|
||||
text.SetText( content );
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
commit.Push( _( "Increment" ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void EDIT_TOOL::PadFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector,
|
||||
PCB_SELECTION_TOOL* sTool )
|
||||
{
|
||||
@ -3368,6 +3436,12 @@ void EDIT_TOOL::setTransitions()
|
||||
Go( &EDIT_TOOL::HealShapes, PCB_ACTIONS::healShapes.MakeEvent() );
|
||||
Go( &EDIT_TOOL::ModifyLines, PCB_ACTIONS::extendLines.MakeEvent() );
|
||||
|
||||
Go( &EDIT_TOOL::Increment, ACTIONS::increment.MakeEvent() );
|
||||
Go( &EDIT_TOOL::Increment, ACTIONS::incrementPrimary.MakeEvent() );
|
||||
Go( &EDIT_TOOL::Increment, ACTIONS::decrementPrimary.MakeEvent() );
|
||||
Go( &EDIT_TOOL::Increment, ACTIONS::incrementSecondary.MakeEvent() );
|
||||
Go( &EDIT_TOOL::Increment, ACTIONS::decrementSecondary.MakeEvent() );
|
||||
|
||||
Go( &EDIT_TOOL::BooleanPolygons, PCB_ACTIONS::mergePolygons.MakeEvent() );
|
||||
Go( &EDIT_TOOL::BooleanPolygons, PCB_ACTIONS::subtractPolygons.MakeEvent() );
|
||||
Go( &EDIT_TOOL::BooleanPolygons, PCB_ACTIONS::intersectPolygons.MakeEvent() );
|
||||
|
@ -175,6 +175,11 @@ public:
|
||||
*/
|
||||
int CreateArray( const TOOL_EVENT& aEvent );
|
||||
|
||||
/**
|
||||
* Increment some aspect of the selected items.q
|
||||
*/
|
||||
int Increment( const TOOL_EVENT& aEvent );
|
||||
|
||||
/**
|
||||
* A selection filter which prunes the selection to contain only items of type #PCB_MODULE_T.
|
||||
*/
|
||||
|
@ -588,6 +588,11 @@ public:
|
||||
|
||||
static TOOL_ACTION repeatLayout;
|
||||
static TOOL_ACTION generatePlacementRuleAreas;
|
||||
|
||||
enum PAD_INCREMENT
|
||||
{
|
||||
NUMBER = 0,
|
||||
};
|
||||
};
|
||||
|
||||
class PCB_EVENTS
|
||||
|
Loading…
Reference in New Issue
Block a user