KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_group_properties.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <tool/tool_manager.h>
25#include <tools/pcb_actions.h>
27#include <pcb_base_edit_frame.h>
28#include <pcb_group.h>
29#include <status_popup.h>
30#include <board_commit.h>
31#include <bitmaps.h>
34
35
37 PCB_GROUP* aGroup ) :
39 m_brdEditor( aParent ),
40 m_toolMgr( aParent->GetToolManager() ),
41 m_group( aGroup )
42{
43 m_bpAddMember->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
44 m_bpRemoveMember->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
45
46 m_nameCtrl->SetValue( m_group->GetName() );
47
48 m_locked->SetValue( m_group->IsLocked() );
49 m_locked->Show( dynamic_cast<PCB_EDIT_FRAME*>( aParent ) != nullptr );
50
51 for( BOARD_ITEM* item : m_group->GetItems() )
52 m_membersList->Append( item->GetItemDescription( m_brdEditor, true ), item );
53
55
57
58 // Now all widgets have the size fixed, call FinishDialogSettings
60}
61
62
64{
65 if( m_brdEditor->IsBeingDeleted() )
66 return;
67
68 m_brdEditor->FocusOnItem( nullptr );
70}
71
72
74{
75 // Don't do anything here; it gets called every time we re-show the dialog after
76 // picking a new member.
77 return true;
78}
79
80
82{
83 BOARD_COMMIT commit( m_brdEditor );
84 commit.Modify( m_group );
85
86 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
87 {
88 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_membersList->GetClientData( ii ) );
89 PCB_GROUP* existingGroup = item->GetParentGroup();
90
91 if( existingGroup != m_group )
92 {
93 commit.Modify( item );
94
95 if( existingGroup )
96 commit.Modify( existingGroup );
97 }
98 }
99
100 m_group->SetName( m_nameCtrl->GetValue() );
101 m_group->SetLocked( m_locked->GetValue() );
102
105
106 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
107 {
108 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_membersList->GetClientData( ii ) );
109 m_group->AddItem( item );
110 }
111
113
114 commit.Push( _( "Edit Group Properties" ) );
115 return true;
116}
117
118
119void DIALOG_GROUP_PROPERTIES::OnMemberSelected( wxCommandEvent& aEvent )
120{
121 int selected = m_membersList->GetSelection();
122
123 if( selected >= 0 )
124 {
125 WINDOW_THAWER thawer( m_brdEditor );
126 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_membersList->GetClientData( selected ) );
127
128 m_brdEditor->FocusOnItem( item );
130 }
131
132 aEvent.Skip();
133}
134
135
136void DIALOG_GROUP_PROPERTIES::OnAddMember( wxCommandEvent& event )
137{
139}
140
141
143{
144
145 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
146 {
147 if( aItem == static_cast<BOARD_ITEM*>( m_membersList->GetClientData( ii ) ) )
148 return;
149 }
150
151 if( aItem == m_group )
152 return;
153
154 m_membersList->Append( aItem->GetItemDescription( m_brdEditor, true ), aItem );
155}
156
157
158void DIALOG_GROUP_PROPERTIES::OnRemoveMember( wxCommandEvent& event )
159{
160 int selected = m_membersList->GetSelection();
161
162 if( selected >= 0 )
163 m_membersList->Delete( selected );
164
165 m_brdEditor->FocusOnItem( nullptr );
167}
168
169
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:90
virtual bool IsLocked() const
Definition: board_item.cpp:75
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
Class DIALOG_GROUP_PROPERTIES_BASE.
DIALOG_GROUP_PROPERTIES(PCB_BASE_EDIT_FRAME *aParent, PCB_GROUP *aTarget)
void OnRemoveMember(wxCommandEvent &event) override
void DoAddMember(EDA_ITEM *aItem)
void OnAddMember(wxCommandEvent &event) override
void OnMemberSelected(wxCommandEvent &event) override
PCB_BASE_EDIT_FRAME * m_brdEditor
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:102
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:111
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:68
static TOOL_ACTION pickNewGroupMember
Definition: pcb_actions.h:311
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:71
Common, abstract interface for edit frames.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void FocusOnItem(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
The main frame for Pcbnew.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:52
std::unordered_set< BOARD_ITEM * > & GetItems()
Definition: pcb_group.h:69
void RemoveAll()
Definition: pcb_group.cpp:109
void SetName(const wxString &aName)
Definition: pcb_group.h:67
virtual bool AddItem(BOARD_ITEM *aItem)
Add item to group.
Definition: pcb_group.cpp:81
wxString GetName() const
Definition: pcb_group.h:66
void SetLocked(bool aLocked) override
Definition: pcb_group.cpp:184
void SetBitmap(const wxBitmapBundle &aBmp)
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
#define _(s)
Class to handle a set of BOARD_ITEMs.