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 m_bpAddMember->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
45 m_bpRemoveMember->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
46
47 m_nameCtrl->SetValue( m_group->GetName() );
48 m_locked->SetValue( aGroup->AsEdaItem()->IsLocked() );
50
51 if( aGroup->AsEdaItem()->Type() != PCB_GROUP_T )
52 m_locked->Hide();
53
54 for( EDA_ITEM* item : m_group->GetItems() )
55 m_membersList->Append( item->GetItemDescription( m_frame, true ), item );
56
58
60
61 // Now all widgets have the size fixed, call FinishDialogSettings
63}
64
65
67{
68 if( m_frame->IsBeingDeleted() )
69 return;
70
73}
74
75
77{
78 // Don't do anything here; it gets called every time we re-show the dialog after
79 // picking a new member.
80 return true;
81}
82
83
85{
86 m_commit->Modify( m_group->AsEdaItem(), m_frame->GetScreen() );
87
88 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
89 {
90 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) );
91 EDA_GROUP* existingGroup = item->GetParentGroup();
92
93 if( existingGroup != m_group )
94 {
95 m_commit->Modify( item, m_frame->GetScreen() );
96
97 if( existingGroup )
98 m_commit->Modify( existingGroup->AsEdaItem(), m_frame->GetScreen() );
99 }
100 }
101
102 m_group->SetName( m_nameCtrl->GetValue() );
103 m_group->AsEdaItem()->SetLocked( m_locked->GetValue() );
104
105 if( !m_libraryLink->GetValue().IsEmpty() )
106 {
107 LIB_ID libId;
108
109 if( libId.Parse( m_libraryLink->GetValue(), true ) >= 0 )
110 {
111 wxString error;
112 error.Printf( _( "Invalid library link: '%s'" ), m_libraryLink->GetValue() );
113 wxMessageBox( error, _( "Error" ), wxOK | wxICON_ERROR, m_frame );
114 return false;
115 }
116
118 }
119 else
121
124
125 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
126 {
127 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) );
128 m_group->AddItem( item );
129 }
130
132
133 m_commit->Push( _( "Edit Group Properties" ) );
134 return true;
135}
136
137
138void DIALOG_GROUP_PROPERTIES::OnMemberSelected( wxCommandEvent& aEvent )
139{
140 int selected = m_membersList->GetSelection();
141
142 if( selected >= 0 )
143 {
144 WINDOW_THAWER thawer( m_frame );
145 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( selected ) );
146
147 m_frame->FocusOnItem( item );
149 }
150
151 aEvent.Skip();
152}
153
154
155void DIALOG_GROUP_PROPERTIES::OnAddMember( wxCommandEvent& event )
156{
158}
159
160
162{
163
164 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
165 {
166 if( aItem == static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) ) )
167 return;
168 }
169
170 if( aItem == m_group->AsEdaItem() )
171 return;
172
173 m_membersList->Append( aItem->GetItemDescription( m_frame, true ), aItem );
174}
175
176
177void DIALOG_GROUP_PROPERTIES::OnRemoveMember( wxCommandEvent& event )
178{
179 int selected = m_membersList->GetSelection();
180
181 if( selected >= 0 )
182 m_membersList->Delete( selected );
183
186}
187
188
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
static TOOL_ACTION pickNewGroupMember
Definition: actions.h:244
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: actions.h:223
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: actions.h:220
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 SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:66
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:88
std::unordered_set< EDA_ITEM * > & GetItems()
Definition: eda_group.h:54
virtual void RemoveAll()=0
wxString GetName() const
Definition: eda_group.h:51
virtual bool AddItem(EDA_ITEM *aItem)=0
Add item to group.
void SetDesignBlockLibId(const LIB_ID &aLibId)
Definition: eda_group.h:86
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:96
virtual void SetLocked(bool aLocked)
Definition: eda_item.h:117
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:118
virtual EDA_GROUP * GetParentGroup() const
Definition: eda_item.h:114
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:108
virtual bool IsLocked() const
Definition: eda_item.h:116
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