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 The 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 <tool/actions.h>
26#include <eda_draw_frame.h>
27#include <eda_group.h>
28#include <status_popup.h>
29#include <commit.h>
30#include <bitmaps.h>
33#include <wx/msgdlg.h>
34
35
37 const std::shared_ptr<COMMIT>& aCommit ) :
39 m_frame( aParent ),
40 m_toolMgr( aParent->GetToolManager() ),
41 m_group( aGroup ),
42 m_commit( aCommit )
43{
44 // Properties dialogs don't really want state-saving/restoring
45 OptOut( this );
46
47 m_bpAddMember->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
48 m_bpRemoveMember->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
49
50 m_nameCtrl->SetValue( m_group->GetName() );
51 m_locked->SetValue( aGroup->AsEdaItem()->IsLocked() );
53
54 if( aGroup->AsEdaItem()->Type() != PCB_GROUP_T )
55 m_locked->Hide();
56
57 for( EDA_ITEM* item : m_group->GetItems() )
58 m_membersList->Append( item->GetItemDescription( m_frame, true ), item );
59
61
63
64 // Now all widgets have the size fixed, call FinishDialogSettings
66}
67
68
70{
71 if( m_frame->IsBeingDeleted() )
72 return;
73
76}
77
78
80{
81 // Don't do anything here; it gets called every time we re-show the dialog after
82 // picking a new member.
83 return true;
84}
85
86
88{
89 m_commit->Modify( m_group->AsEdaItem(), m_frame->GetScreen(), RECURSE_MODE::RECURSE );
90
91 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
92 {
93 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) );
94 EDA_GROUP* existingGroup = item->GetParentGroup();
95
96 if( existingGroup != m_group )
97 {
98 m_commit->Modify( item, m_frame->GetScreen() );
99
100 if( existingGroup )
101 m_commit->Modify( existingGroup->AsEdaItem(), m_frame->GetScreen(), RECURSE_MODE::NO_RECURSE );
102 }
103 }
104
105 m_group->SetName( m_nameCtrl->GetValue() );
106 m_group->AsEdaItem()->SetLocked( m_locked->GetValue() );
107
108 if( !m_libraryLink->GetValue().IsEmpty() )
109 {
110 LIB_ID libId;
111
112 if( libId.Parse( m_libraryLink->GetValue(), true ) >= 0 )
113 {
114 wxString error;
115 error.Printf( _( "Invalid library link: '%s'" ), m_libraryLink->GetValue() );
116 wxMessageBox( error, _( "Error" ), wxOK | wxICON_ERROR, m_frame );
117 return false;
118 }
119
121 }
122 else
123 {
125 }
126
129
130 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
131 {
132 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) );
133 m_group->AddItem( item );
134 }
135
137
138 m_commit->Push( _( "Edit Group Properties" ) );
139 return true;
140}
141
142
143void DIALOG_GROUP_PROPERTIES::OnMemberSelected( wxCommandEvent& aEvent )
144{
145 int selected = m_membersList->GetSelection();
146
147 if( selected >= 0 )
148 {
149 WINDOW_THAWER thawer( m_frame );
150 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( selected ) );
151
152 m_frame->FocusOnItem( item );
154 }
155
156 aEvent.Skip();
157}
158
159
160void DIALOG_GROUP_PROPERTIES::OnAddMember( wxCommandEvent& event )
161{
163}
164
165
167{
168
169 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
170 {
171 if( aItem == static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) ) )
172 return;
173 }
174
175 if( aItem == m_group->AsEdaItem() )
176 return;
177
178 m_membersList->Append( aItem->GetItemDescription( m_frame, true ), aItem );
179}
180
181
182void DIALOG_GROUP_PROPERTIES::OnRemoveMember( wxCommandEvent& event )
183{
184 int selected = m_membersList->GetSelection();
185
186 if( selected >= 0 )
187 m_membersList->Delete( selected );
188
191}
192
193
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
static TOOL_ACTION pickNewGroupMember
Definition: actions.h:245
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: actions.h:224
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: actions.h:221
Class DIALOG_GROUP_PROPERTIES_BASE.
void OnRemoveMember(wxCommandEvent &event) override
void DoAddMember(EDA_ITEM *aItem)
void OnAddMember(wxCommandEvent &event) override
void OnMemberSelected(wxCommandEvent &event) override
DIALOG_GROUP_PROPERTIES(EDA_DRAW_FRAME *aParent, EDA_GROUP *aTarget, const std::shared_ptr< COMMIT > &aCommit)
std::shared_ptr< COMMIT > m_commit
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:75
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...
The base class for create windows for drawing purpose.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void FocusOnItem(EDA_ITEM *aItem)
Focus on a particular canvas item.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void ClearFocus()
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A set of EDA_ITEMs (i.e., without duplicates).
Definition: eda_group.h:46
const LIB_ID & GetDesignBlockLibId() const
Definition: eda_group.h:73
std::unordered_set< EDA_ITEM * > & GetItems()
Definition: eda_group.h:54
wxString GetName() const
Definition: eda_group.h:51
void RemoveAll()
Definition: eda_group.cpp:49
void SetDesignBlockLibId(const LIB_ID &aLibId)
Definition: eda_group.h:72
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition: eda_group.cpp:27
virtual EDA_ITEM * AsEdaItem()=0
void SetName(const wxString &aName)
Definition: eda_group.h:52
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:98
virtual void SetLocked(bool aLocked)
Definition: eda_item.h:121
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:144
virtual EDA_GROUP * GetParentGroup() const
Definition: eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
virtual bool IsLocked() const
Definition: eda_item.h:120
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:52
UTF8 Format() const
Definition: lib_id.cpp:119
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)
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:110