KiCad PCB EDA Suite
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 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>
26 #include <tools/pcb_picker_tool.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>
33 
34 
36  PCB_GROUP* aGroup ) :
38  m_brdEditor( aParent ),
39  m_toolMgr( aParent->GetToolManager() ),
40  m_group( aGroup )
41 {
42  m_bpAddMember->SetBitmap( KiBitmap( small_plus_xpm ) );
43  m_bpRemoveMember->SetBitmap( KiBitmap( small_trash_xpm ) );
44 
45  m_nameCtrl->SetValue( m_group->GetName() );
46 
47  for( BOARD_ITEM* item : m_group->GetItems() )
48  m_membersList->Append( item->GetSelectMenuText( m_brdEditor->GetUserUnits() ), item );
49 
50  m_sdbSizerOK->SetDefault();
51 
53 
54  // Now all widgets have the size fixed, call FinishDialogSettings
56 }
57 
58 
60 {
61  m_brdEditor->FocusOnItem( nullptr );
63 }
64 
65 
67 {
68  // Don't do anything here; it gets called every time we re-show the dialog after
69  // picking a new member.
70  return true;
71 }
72 
73 
75 {
76  BOARD_COMMIT commit( m_brdEditor );
77  commit.Modify( m_group );
78 
80  [&]( BOARD_ITEM* descendant )
81  {
82  commit.Modify( descendant );
83  } );
84 
85  for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
86  {
87  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_membersList->GetClientData( ii ) );
88  PCB_GROUP* existingGroup = item->GetParentGroup();
89 
90  if( existingGroup != m_group )
91  {
92  commit.Modify( item );
93 
94  if( existingGroup )
95  commit.Modify( existingGroup );
96  }
97  }
98 
99  m_group->SetName( m_nameCtrl->GetValue() );
100 
102  m_group->RemoveAll();
103 
104  for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
105  {
106  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_membersList->GetClientData( ii ) );
107  m_group->AddItem( item );
108  }
109 
111 
112  commit.Push( _( "Modified group" ) );
113  return true;
114 }
115 
116 
117 void DIALOG_GROUP_PROPERTIES::OnMemberSelected( wxCommandEvent& aEvent )
118 {
119  int selected = m_membersList->GetSelection();
120 
121  if( selected >= 0 )
122  {
123  WINDOW_THAWER thawer( m_brdEditor );
124  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_membersList->GetClientData( selected ) );
125 
126  m_brdEditor->FocusOnItem( item );
128  }
129 
130  aEvent.Skip();
131 }
132 
133 
134 void DIALOG_GROUP_PROPERTIES::OnAddMember( wxCommandEvent& event )
135 {
137 }
138 
139 
141 {
142  for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
143  {
144  if( aItem == static_cast<BOARD_ITEM*>( m_membersList->GetClientData( ii ) ) )
145  return;
146  }
147 
148  if( aItem == m_group )
149  return;
150 
151  m_membersList->Append( aItem->GetSelectMenuText( m_brdEditor->GetUserUnits() ), aItem );
152 }
153 
154 
155 void DIALOG_GROUP_PROPERTIES::OnRemoveMember( wxCommandEvent& event )
156 {
157  int selected = m_membersList->GetSelection();
158 
159  if( selected >= 0 )
160  m_membersList->Delete( selected );
161 
162  m_brdEditor->FocusOnItem( nullptr );
164 }
165 
166 
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:93
void RemoveAll()
Definition: pcb_group.cpp:63
bool AddItem(BOARD_ITEM *aItem)
Add item to group.
Definition: pcb_group.cpp:38
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
void OnAddMember(wxCommandEvent &event) override
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
std::unordered_set< BOARD_ITEM * > & GetItems()
Definition: pcb_group.h:68
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:98
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
wxString GetName() const
Definition: pcb_group.h:65
void OnRemoveMember(wxCommandEvent &event) override
static TOOL_ACTION pickNewGroupMember
Definition: pcb_actions.h:221
void DoAddMember(EDA_ITEM *aItem)
void RunOnDescendants(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all descendants of the group.
Definition: pcb_group.cpp:324
void OnMemberSelected(wxCommandEvent &event) override
const BITMAP_OPAQUE small_trash_xpm[1]
Definition: small_trash.cpp:23
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
DIALOG_GROUP_PROPERTIES(PCB_BASE_EDIT_FRAME *aParent, PCB_GROUP *aTarget)
Common, abstract interface for edit frames.
#define _(s)
Definition: 3d_actions.cpp:33
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: eda_item.cpp:123
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:66
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
PCB_BASE_EDIT_FRAME * m_brdEditor
Class DIALOG_GROUP_PROPERTIES_BASE.
void FocusOnItem(BOARD_ITEM *aItem)
const BITMAP_OPAQUE small_plus_xpm[1]
Definition: small_plus.cpp:18
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
void SetName(wxString aName)
Definition: pcb_group.h:66