mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
groups: add ability to add selection to group
This commit is contained in:
parent
195e79ae46
commit
3c5a48868b
@ -209,6 +209,13 @@ TOOL_ACTION ACTIONS::ungroup( TOOL_ACTION_ARGS()
|
|||||||
.Tooltip( _( "Ungroup any selected groups" ) )
|
.Tooltip( _( "Ungroup any selected groups" ) )
|
||||||
.Icon( BITMAPS::group_ungroup ) );
|
.Icon( BITMAPS::group_ungroup ) );
|
||||||
|
|
||||||
|
TOOL_ACTION ACTIONS::addToGroup( TOOL_ACTION_ARGS()
|
||||||
|
.Name( "common.Interactive.addToGroup" )
|
||||||
|
.Scope( AS_GLOBAL )
|
||||||
|
.FriendlyName( _( "Add Items" ) )
|
||||||
|
.Tooltip( _( "Add items to group" ) )
|
||||||
|
.Icon( BITMAPS::group_remove ) );
|
||||||
|
|
||||||
TOOL_ACTION ACTIONS::removeFromGroup( TOOL_ACTION_ARGS()
|
TOOL_ACTION ACTIONS::removeFromGroup( TOOL_ACTION_ARGS()
|
||||||
.Name( "common.Interactive.removeFromGroup" )
|
.Name( "common.Interactive.removeFromGroup" )
|
||||||
.Scope( AS_GLOBAL )
|
.Scope( AS_GLOBAL )
|
||||||
|
@ -44,6 +44,7 @@ public:
|
|||||||
|
|
||||||
Add( ACTIONS::group );
|
Add( ACTIONS::group );
|
||||||
Add( ACTIONS::ungroup );
|
Add( ACTIONS::ungroup );
|
||||||
|
Add( ACTIONS::addToGroup );
|
||||||
Add( ACTIONS::removeFromGroup );
|
Add( ACTIONS::removeFromGroup );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,6 +63,8 @@ private:
|
|||||||
bool canGroup = false;
|
bool canGroup = false;
|
||||||
bool hasGroup = false;
|
bool hasGroup = false;
|
||||||
bool hasMember = false;
|
bool hasMember = false;
|
||||||
|
bool onlyOneGroup = false;
|
||||||
|
bool hasUngroupedItems = false;
|
||||||
|
|
||||||
if( m_selectionTool != nullptr )
|
if( m_selectionTool != nullptr )
|
||||||
{
|
{
|
||||||
@ -70,7 +73,18 @@ private:
|
|||||||
canGroup = true;
|
canGroup = true;
|
||||||
|
|
||||||
if( item->Type() == PCB_GROUP_T || item->Type() == SCH_GROUP_T )
|
if( item->Type() == PCB_GROUP_T || item->Type() == SCH_GROUP_T )
|
||||||
hasGroup = true;
|
{
|
||||||
|
// Only allow one group to be selected for adding to existing group
|
||||||
|
if( hasGroup )
|
||||||
|
onlyOneGroup = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
onlyOneGroup = true;
|
||||||
|
hasGroup = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( !item->GetParentGroup() )
|
||||||
|
hasUngroupedItems = true;
|
||||||
|
|
||||||
if( item->GetParentGroup() )
|
if( item->GetParentGroup() )
|
||||||
hasMember = true;
|
hasMember = true;
|
||||||
@ -79,6 +93,7 @@ private:
|
|||||||
|
|
||||||
Enable( ACTIONS::group.GetUIId(), canGroup );
|
Enable( ACTIONS::group.GetUIId(), canGroup );
|
||||||
Enable( ACTIONS::ungroup.GetUIId(), hasGroup );
|
Enable( ACTIONS::ungroup.GetUIId(), hasGroup );
|
||||||
|
Enable( ACTIONS::addToGroup.GetUIId(), onlyOneGroup && hasUngroupedItems );
|
||||||
Enable( ACTIONS::removeFromGroup.GetUIId(), hasMember );
|
Enable( ACTIONS::removeFromGroup.GetUIId(), hasMember );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +190,47 @@ int GROUP_TOOL::Ungroup( const TOOL_EVENT& aEvent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int GROUP_TOOL::AddToGroup( const TOOL_EVENT& aEvent )
|
||||||
|
{
|
||||||
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
||||||
|
|
||||||
|
EDA_ITEM* group = nullptr;
|
||||||
|
EDA_ITEMS toAdd;
|
||||||
|
|
||||||
|
for( EDA_ITEM* item : selection )
|
||||||
|
{
|
||||||
|
if( item->Type() == PCB_GROUP_T || item->Type() == SCH_GROUP_T )
|
||||||
|
{
|
||||||
|
// Only allow one group to be selected for adding to existing group
|
||||||
|
if( group != nullptr )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
group = item;
|
||||||
|
}
|
||||||
|
else if( !item->GetParentGroup() )
|
||||||
|
toAdd.push_back( item );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !group || toAdd.empty() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
m_toolMgr->RunAction( ACTIONS::selectionClear );
|
||||||
|
|
||||||
|
m_commit->Modify( group, m_frame->GetScreen() );
|
||||||
|
|
||||||
|
for( EDA_ITEM* item : toAdd )
|
||||||
|
m_commit->Stage( item, CHT_GROUP, m_frame->GetScreen() );
|
||||||
|
|
||||||
|
m_commit->Push( _( "Add Items to Group" ) );
|
||||||
|
|
||||||
|
m_selectionTool->AddItemToSel( group );
|
||||||
|
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
|
||||||
|
m_frame->OnModify();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int GROUP_TOOL::RemoveFromGroup( const TOOL_EVENT& aEvent )
|
int GROUP_TOOL::RemoveFromGroup( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
const SELECTION& selection = m_selectionTool->GetSelection();
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
||||||
@ -225,6 +281,7 @@ void GROUP_TOOL::setTransitions()
|
|||||||
|
|
||||||
Go( &GROUP_TOOL::Group, ACTIONS::group.MakeEvent() );
|
Go( &GROUP_TOOL::Group, ACTIONS::group.MakeEvent() );
|
||||||
Go( &GROUP_TOOL::Ungroup, ACTIONS::ungroup.MakeEvent() );
|
Go( &GROUP_TOOL::Ungroup, ACTIONS::ungroup.MakeEvent() );
|
||||||
|
Go( &GROUP_TOOL::AddToGroup, ACTIONS::addToGroup.MakeEvent() );
|
||||||
Go( &GROUP_TOOL::RemoveFromGroup, ACTIONS::removeFromGroup.MakeEvent() );
|
Go( &GROUP_TOOL::RemoveFromGroup, ACTIONS::removeFromGroup.MakeEvent() );
|
||||||
Go( &GROUP_TOOL::EnterGroup, ACTIONS::groupEnter.MakeEvent() );
|
Go( &GROUP_TOOL::EnterGroup, ACTIONS::groupEnter.MakeEvent() );
|
||||||
Go( &GROUP_TOOL::LeaveGroup, ACTIONS::groupLeave.MakeEvent() );
|
Go( &GROUP_TOOL::LeaveGroup, ACTIONS::groupLeave.MakeEvent() );
|
||||||
|
@ -52,6 +52,9 @@ public:
|
|||||||
///< Ungroup selected items.
|
///< Ungroup selected items.
|
||||||
virtual int Ungroup( const TOOL_EVENT& aEvent );
|
virtual int Ungroup( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
///< Add selection to group.
|
||||||
|
virtual int AddToGroup( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
///< Remove selection from group.
|
///< Remove selection from group.
|
||||||
virtual int RemoveFromGroup( const TOOL_EVENT& aEvent );
|
virtual int RemoveFromGroup( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
@ -65,6 +68,10 @@ protected:
|
|||||||
///< Set up handlers for various events.
|
///< Set up handlers for various events.
|
||||||
void setTransitions() override;
|
void setTransitions() override;
|
||||||
|
|
||||||
|
///< Get the correctly casted group type from the item.
|
||||||
|
/// Works around our lack of working dynamic_cast.
|
||||||
|
virtual EDA_GROUP* getGroupFromItem( EDA_ITEM* ) = 0;
|
||||||
|
|
||||||
///< Subclasses implement to provide correct *_COMMIT object type
|
///< Subclasses implement to provide correct *_COMMIT object type
|
||||||
virtual std::shared_ptr<COMMIT> createCommit() = 0;
|
virtual std::shared_ptr<COMMIT> createCommit() = 0;
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <tool/group_tool.h>
|
#include <tool/group_tool.h>
|
||||||
#include <sch_commit.h>
|
#include <sch_commit.h>
|
||||||
|
#include <sch_group.h>
|
||||||
|
|
||||||
class SCH_GROUP_TOOL : public GROUP_TOOL
|
class SCH_GROUP_TOOL : public GROUP_TOOL
|
||||||
{
|
{
|
||||||
@ -14,4 +15,12 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<COMMIT> createCommit() override { return std::make_shared<SCH_COMMIT>( m_toolMgr ); }
|
std::shared_ptr<COMMIT> createCommit() override { return std::make_shared<SCH_COMMIT>( m_toolMgr ); }
|
||||||
|
|
||||||
|
EDA_GROUP* getGroupFromItem( EDA_ITEM* aItem ) override
|
||||||
|
{
|
||||||
|
if( aItem->Type() == SCH_GROUP_T )
|
||||||
|
return static_cast<SCH_GROUP*>( aItem );
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -234,6 +234,7 @@ public:
|
|||||||
// Grouping
|
// Grouping
|
||||||
static TOOL_ACTION group;
|
static TOOL_ACTION group;
|
||||||
static TOOL_ACTION ungroup;
|
static TOOL_ACTION ungroup;
|
||||||
|
static TOOL_ACTION addToGroup;
|
||||||
static TOOL_ACTION removeFromGroup;
|
static TOOL_ACTION removeFromGroup;
|
||||||
static TOOL_ACTION groupEnter;
|
static TOOL_ACTION groupEnter;
|
||||||
static TOOL_ACTION groupLeave;
|
static TOOL_ACTION groupLeave;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <tool/group_tool.h>
|
#include <tool/group_tool.h>
|
||||||
#include <board_commit.h>
|
#include <board_commit.h>
|
||||||
|
#include <pcb_group.h>
|
||||||
|
|
||||||
class PCB_GROUP_TOOL : public GROUP_TOOL
|
class PCB_GROUP_TOOL : public GROUP_TOOL
|
||||||
{
|
{
|
||||||
@ -14,4 +15,12 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<COMMIT> createCommit() override { return std::make_shared<BOARD_COMMIT>( this ); }
|
std::shared_ptr<COMMIT> createCommit() override { return std::make_shared<BOARD_COMMIT>( this ); }
|
||||||
|
|
||||||
|
EDA_GROUP* getGroupFromItem( EDA_ITEM* aItem ) override
|
||||||
|
{
|
||||||
|
if( aItem->Type() == PCB_GROUP_T )
|
||||||
|
return static_cast<PCB_GROUP*>( aItem );
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user