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 m_commit->Modify( m_group->AsEdaItem(), m_frame->GetScreen(), RECURSE_MODE::RECURSE );
86
87 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
88 {
89 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) );
90 EDA_GROUP* existingGroup = item->GetParentGroup();
91
92 if( existingGroup != m_group )
93 {
94 m_commit->Modify( item, m_frame->GetScreen() );
95
96 if( existingGroup )
97 m_commit->Modify( existingGroup->AsEdaItem(), m_frame->GetScreen(), RECURSE_MODE::NO_RECURSE );
98 }
99 }
100
101 m_group->SetName( m_nameCtrl->GetValue() );
102 m_group->AsEdaItem()->SetLocked( m_locked->GetValue() );
103
104 if( !m_libraryLink->GetValue().IsEmpty() )
105 {
106 LIB_ID libId;
107
108 if( libId.Parse( m_libraryLink->GetValue(), true ) >= 0 )
109 {
110 wxString error;
111 error.Printf( _( "Invalid library link: '%s'" ), m_libraryLink->GetValue() );
112 wxMessageBox( error, _( "Error" ), wxOK | wxICON_ERROR, m_frame );
113 return false;
114 }
115
116 m_group->SetDesignBlockLibId( libId );
117 }
118 else
119 {
120 m_group->SetDesignBlockLibId( LIB_ID() );
121 }
122
124 m_group->RemoveAll();
125
126 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
127 {
128 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) );
129 m_group->AddItem( item );
130 }
131
132 m_toolMgr->RunAction<EDA_ITEM*>( ACTIONS::selectItem, m_group->AsEdaItem() );
133
134 m_commit->Push( _( "Edit Group Properties" ) );
135 return true;
136}
137
138
139void DIALOG_GROUP_PROPERTIES::OnMemberSelected( wxCommandEvent& aEvent )
140{
141 int selected = m_membersList->GetSelection();
142
143 if( selected >= 0 )
144 {
145 WINDOW_THAWER thawer( m_frame );
146 EDA_ITEM* item = static_cast<EDA_ITEM*>( m_membersList->GetClientData( selected ) );
147
148 m_frame->FocusOnItem( item );
149 m_frame->GetCanvas()->Refresh();
150 }
151
152 aEvent.Skip();
153}
154
155
156void DIALOG_GROUP_PROPERTIES::OnAddMember( wxCommandEvent& event )
157{
159}
160
161
163{
164
165 for( size_t ii = 0; ii < m_membersList->GetCount(); ++ii )
166 {
167 if( aItem == static_cast<EDA_ITEM*>( m_membersList->GetClientData( ii ) ) )
168 return;
169 }
170
171 if( aItem == m_group->AsEdaItem() )
172 {
173 m_frame->ShowInfoBarWarning( _( "A group cannot contain itself." ) );
174 return;
175 }
176
177 if( const EDA_GROUP* group = dynamic_cast<const EDA_GROUP*>( aItem ) )
178 {
179 if( group->ContainsItem( m_group->AsEdaItem() ) )
180 {
181 m_frame->ShowInfoBarWarning( _( "Cannot add this group because it already contains the current group." ) );
182 return;
183 }
184 }
185
186 m_membersList->Append( aItem->GetItemDescription( m_frame, true ), aItem );
187}
188
189
190void DIALOG_GROUP_PROPERTIES::OnRemoveMember( wxCommandEvent& event )
191{
192 int selected = m_membersList->GetSelection();
193
194 if( selected >= 0 )
195 m_membersList->Delete( selected );
196
197 m_frame->ClearFocus();
198 m_frame->GetCanvas()->Refresh();
199}
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:79
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:42
virtual EDA_ITEM * AsEdaItem()=0
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition eda_item.cpp:169
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:125
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:48
#define _(s)
@ RECURSE
Definition eda_item.h:49
@ NO_RECURSE
Definition eda_item.h:50
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:104