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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <tool/tool_manager.h>
21#include <tool/actions.h>
22#include <eda_draw_frame.h>
23#include <eda_group.h>
24#include <status_popup.h>
25#include <commit.h>
26#include <bitmaps.h>
29#include <wx/msgdlg.h>
30
31
33 const std::shared_ptr<COMMIT>& aCommit ) :
35 m_frame( aParent ),
36 m_toolMgr( aParent->GetToolManager() ),
37 m_group( aGroup ),
38 m_commit( aCommit )
39{
40 // Properties dialogs don't really want state-saving/restoring
41 OptOut( this );
42
45
46 m_nameCtrl->SetValue( m_group->GetName() );
47 m_locked->SetValue( aGroup->AsEdaItem()->IsLocked() );
48 m_libraryLink->SetValue( m_group->GetDesignBlockLibId().Format() );
49
50 if( aGroup->AsEdaItem()->Type() != PCB_GROUP_T )
51 m_locked->Hide();
52
53 for( EDA_ITEM* item : m_group->GetItems() )
54 m_membersList->Append( item->GetItemDescription( m_frame, true ), item );
55
57
59
60 // Now all widgets have the size fixed, call FinishDialogSettings
62}
63
64
66{
67 if( m_frame->IsBeingDeleted() )
68 return;
69
70 m_frame->ClearFocus();
71 m_frame->GetCanvas()->Refresh();
72}
73
74
76{
77 // Don't do anything here; it gets called every time we re-show the dialog after
78 // picking a new member.
79 return true;
80}
81
82
84{
85 LIB_ID libId;
86
87 if( !m_libraryLink->GetValue().IsEmpty() && libId.Parse( m_libraryLink->GetValue(), true ) >= 0 )
88 {
89 wxString error;
90 error.Printf( _( "Invalid library link: '%s'" ), m_libraryLink->GetValue() );
91 wxMessageBox( error, _( "Error" ), wxOK | wxICON_ERROR, m_frame );
92 return false;
93 }
94
95 m_commit->Modify( m_group->AsEdaItem(), m_frame->GetScreen(), RECURSE_MODE::RECURSE );
96
97 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
98 {
99 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) );
100 EDA_GROUP* existingGroup = item->GetParentGroup();
101
102 if( existingGroup != m_group )
103 {
104 m_commit->Modify( item, m_frame->GetScreen() );
105
106 if( existingGroup )
107 m_commit->Modify( existingGroup->AsEdaItem(), m_frame->GetScreen(), RECURSE_MODE::NO_RECURSE );
108 }
109 }
110
111 m_group->SetName( m_nameCtrl->GetValue() );
112 m_group->AsEdaItem()->SetLocked( m_locked->GetValue() );
113 m_group->SetDesignBlockLibId( libId );
114
116 m_group->RemoveAll();
117
118 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
119 {
120 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) );
121 m_group->AddItem( item );
122 }
123
124 m_toolMgr->RunAction<EDA_ITEM*>( ACTIONS::selectItem, m_group->AsEdaItem() );
125
126 m_commit->Push( _( "Edit Group Properties" ) );
127 return true;
128}
129
130
131void DIALOG_GROUP_PROPERTIES::OnMemberSelected( wxCommandEvent& aEvent )
132{
133 int selected = m_membersList->GetSelection();
134
135 if( selected >= 0 )
136 {
137 WINDOW_THAWER thawer( m_frame );
138 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( selected ) );
139
140 m_frame->FocusOnItem( item );
141 m_frame->GetCanvas()->Refresh();
142 }
143
144 aEvent.Skip();
145}
146
147
148void DIALOG_GROUP_PROPERTIES::OnAddMember( wxCommandEvent& event )
149{
151}
152
153
155{
156
157 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
158 {
159 if( aItem == static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) ) )
160 return;
161 }
162
163 if( aItem == m_group->AsEdaItem() )
164 {
165 m_frame->ShowInfoBarWarning( _( "A group cannot contain itself." ) );
166 return;
167 }
168
169 if( const EDA_GROUP* group = dynamic_cast<const EDA_GROUP*>( aItem ) )
170 {
171 if( group->ContainsItem( m_group->AsEdaItem() ) )
172 {
173 m_frame->ShowInfoBarWarning( _( "Cannot add this group because it already contains the current group." ) );
174 return;
175 }
176 }
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
189 m_frame->ClearFocus();
190 m_frame->GetCanvas()->Refresh();
191}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
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
DIALOG_GROUP_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Group Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void OnRemoveMember(wxCommandEvent &event) override
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:94
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.
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
virtual EDA_ITEM * AsEdaItem()=0
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition eda_item.cpp:304
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:127
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:65
#define _(s)
@ RECURSE
Definition eda_item.h:51
@ NO_RECURSE
Definition eda_item.h:52
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103