2020-12-28 22:16:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-12-13 20:47:28 +00:00
|
|
|
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-12-28 22:16:21 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <tools/pcb_picker_tool.h>
|
2021-01-31 14:50:19 +00:00
|
|
|
#include <pcb_base_edit_frame.h>
|
|
|
|
#include <pcb_group.h>
|
2020-12-28 22:16:21 +00:00
|
|
|
#include <status_popup.h>
|
|
|
|
#include <board_commit.h>
|
|
|
|
#include <bitmaps.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2020-12-28 22:16:21 +00:00
|
|
|
#include <dialogs/dialog_group_properties.h>
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_GROUP_PROPERTIES::DIALOG_GROUP_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent,
|
|
|
|
PCB_GROUP* aGroup ) :
|
|
|
|
DIALOG_GROUP_PROPERTIES_BASE( aParent ),
|
|
|
|
m_brdEditor( aParent ),
|
|
|
|
m_toolMgr( aParent->GetToolManager() ),
|
|
|
|
m_group( aGroup )
|
|
|
|
{
|
2023-10-21 18:56:19 +00:00
|
|
|
m_bpAddMember->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
|
|
|
|
m_bpRemoveMember->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
|
2020-12-28 22:16:21 +00:00
|
|
|
|
|
|
|
m_nameCtrl->SetValue( m_group->GetName() );
|
2021-10-31 16:32:24 +00:00
|
|
|
|
2021-07-22 11:45:33 +00:00
|
|
|
m_locked->SetValue( m_group->IsLocked() );
|
2021-10-31 16:32:24 +00:00
|
|
|
m_locked->Show( dynamic_cast<PCB_EDIT_FRAME*>( aParent ) != nullptr );
|
2020-12-28 22:16:21 +00:00
|
|
|
|
|
|
|
for( BOARD_ITEM* item : m_group->GetItems() )
|
2023-01-12 03:27:44 +00:00
|
|
|
m_membersList->Append( item->GetItemDescription( m_brdEditor ), item );
|
2020-12-28 22:16:21 +00:00
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2020-12-28 22:16:21 +00:00
|
|
|
|
|
|
|
SetInitialFocus( m_nameCtrl );
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
finishDialogSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-29 12:33:37 +00:00
|
|
|
DIALOG_GROUP_PROPERTIES::~DIALOG_GROUP_PROPERTIES()
|
|
|
|
{
|
2021-04-25 20:15:19 +00:00
|
|
|
if( m_brdEditor->IsBeingDeleted() )
|
|
|
|
return;
|
|
|
|
|
2020-12-29 12:33:37 +00:00
|
|
|
m_brdEditor->FocusOnItem( nullptr );
|
|
|
|
m_brdEditor->GetCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-28 22:16:21 +00:00
|
|
|
bool DIALOG_GROUP_PROPERTIES::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
// Don't do anything here; it gets called every time we re-show the dialog after
|
|
|
|
// picking a new member.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_GROUP_PROPERTIES::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
BOARD_COMMIT commit( m_brdEditor );
|
|
|
|
commit.Modify( m_group );
|
|
|
|
|
2020-12-29 12:33:37 +00:00
|
|
|
m_group->RunOnDescendants(
|
|
|
|
[&]( BOARD_ITEM* descendant )
|
|
|
|
{
|
|
|
|
commit.Modify( descendant );
|
|
|
|
} );
|
2020-12-28 22:16:21 +00:00
|
|
|
|
|
|
|
for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_membersList->GetClientData( ii ) );
|
|
|
|
PCB_GROUP* existingGroup = item->GetParentGroup();
|
|
|
|
|
2020-12-29 12:33:37 +00:00
|
|
|
if( existingGroup != m_group )
|
2020-12-28 22:16:21 +00:00
|
|
|
{
|
2020-12-29 12:33:37 +00:00
|
|
|
commit.Modify( item );
|
|
|
|
|
|
|
|
if( existingGroup )
|
|
|
|
commit.Modify( existingGroup );
|
2020-12-28 22:16:21 +00:00
|
|
|
}
|
2020-12-29 12:33:37 +00:00
|
|
|
}
|
2020-12-28 22:16:21 +00:00
|
|
|
|
2020-12-29 12:33:37 +00:00
|
|
|
m_group->SetName( m_nameCtrl->GetValue() );
|
2021-07-22 11:45:33 +00:00
|
|
|
m_group->SetLocked( m_locked->GetValue() );
|
2020-12-29 12:33:37 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2020-12-29 12:33:37 +00:00
|
|
|
m_group->RemoveAll();
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_membersList->GetClientData( ii ) );
|
2020-12-28 22:16:21 +00:00
|
|
|
m_group->AddItem( item );
|
|
|
|
}
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, m_group );
|
2020-12-28 22:16:21 +00:00
|
|
|
|
2020-12-29 12:33:37 +00:00
|
|
|
commit.Push( _( "Modified group" ) );
|
2020-12-28 22:16:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GROUP_PROPERTIES::OnMemberSelected( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
int selected = m_membersList->GetSelection();
|
|
|
|
|
|
|
|
if( selected >= 0 )
|
|
|
|
{
|
|
|
|
WINDOW_THAWER thawer( m_brdEditor );
|
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_membersList->GetClientData( selected ) );
|
|
|
|
|
|
|
|
m_brdEditor->FocusOnItem( item );
|
|
|
|
m_brdEditor->GetCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GROUP_PROPERTIES::OnAddMember( wxCommandEvent& event )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::pickNewGroupMember );
|
2020-12-28 22:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GROUP_PROPERTIES::DoAddMember( EDA_ITEM* aItem )
|
|
|
|
{
|
2023-01-05 23:28:31 +00:00
|
|
|
|
2020-12-28 22:16:21 +00:00
|
|
|
for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
if( aItem == static_cast<BOARD_ITEM*>( m_membersList->GetClientData( ii ) ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aItem == m_group )
|
|
|
|
return;
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
m_membersList->Append( aItem->GetItemDescription( m_brdEditor ), aItem );
|
2020-12-28 22:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GROUP_PROPERTIES::OnRemoveMember( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
int selected = m_membersList->GetSelection();
|
|
|
|
|
|
|
|
if( selected >= 0 )
|
|
|
|
m_membersList->Delete( selected );
|
2020-12-29 12:33:37 +00:00
|
|
|
|
|
|
|
m_brdEditor->FocusOnItem( nullptr );
|
|
|
|
m_brdEditor->GetCanvas()->Refresh();
|
2020-12-28 22:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|