KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_group_tool.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#include <kiplatform/ui.h>
24#include <tool/tool_manager.h>
28#include <status_popup.h>
29#include <board_commit.h>
31#include <pcb_group.h>
32#include <collectors.h>
33#include <footprint.h>
34
35
37{
38 bool isFootprintEditor = m_frame->GetFrameType() == FRAME_FOOTPRINT_EDITOR;
41
42 STATUS_TEXT_POPUP statusPopup( m_frame );
43 bool done = false;
44
46 m_propertiesDialog->Show( false );
47
48 Activate();
49
50 statusPopup.SetText( _( "Click on new member..." ) );
51
52 picker->SetClickHandler(
53 [&]( const VECTOR2D& aPoint ) -> bool
54 {
56
57 const PCB_SELECTION& sel = selTool->RequestSelection(
58 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
59 {
60 } );
61
62 if( sel.Empty() )
63 return true; // still looking for an item
64
65 statusPopup.Hide();
66
68 {
69 EDA_ITEM* elem = sel.Front();
70
71 if( !isFootprintEditor )
72 {
73 while( elem->GetParent() && elem->GetParent()->Type() != PCB_T )
74 elem = elem->GetParent();
75 }
76
78 m_propertiesDialog->Show( true );
79 }
80
81 return false; // got our item; don't need any more
82 } );
83
84 picker->SetMotionHandler(
85 [&]( const VECTOR2D& aPos )
86 {
87 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, -50 ) );
88 } );
89
90 picker->SetCancelHandler(
91 [&]()
92 {
93 if( m_propertiesDialog )
94 m_propertiesDialog->Show( true );
95
96 statusPopup.Hide();
97 } );
98
99 picker->SetFinalizeHandler(
100 [&]( const int& aFinalState )
101 {
102 done = true;
103 } );
104
105 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, -50 ) );
106 statusPopup.Popup();
107 m_frame->GetCanvas()->SetStatusPopup( statusPopup.GetPanel() );
108
109 m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
110
111 while( !done )
112 {
113 // Pass events unless we receive a null event, then we must shut down
114 if( TOOL_EVENT* evt = Wait() )
115 evt->SetPassEvent();
116 else
117 break;
118 }
119
120 m_frame->GetCanvas()->SetStatusPopup( nullptr );
121
122 return 0;
123}
124
125
127{
128 bool isFootprintEditor = m_frame->GetFrameType() == FRAME_FOOTPRINT_EDITOR;
130 PCB_SELECTION selection;
131
132 if( isFootprintEditor )
133 {
134 selection = selTool->RequestSelection(
135 []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* )
136 {
137 } );
138 }
139 else
140 {
141 selection = selTool->RequestSelection(
142 []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* )
143 {
144 // Iterate from the back so we don't have to worry about removals.
145 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
146 {
147 BOARD_ITEM* item = aCollector[i];
148
149 if( item->GetParentFootprint() )
150 aCollector.Remove( item );
151 }
152 } );
153 }
154
155 if( selection.Empty() )
156 return 0;
157
158 BOARD* board = getModel<BOARD>();
159 PCB_GROUP* group = nullptr;
160
161 if( isFootprintEditor )
162 group = new PCB_GROUP( board->GetFirstFootprint() );
163 else
164 group = new PCB_GROUP( board );
165
166 for( EDA_ITEM* eda_item : selection )
167 {
168 if( eda_item->IsBOARD_ITEM() )
169 {
170 if( static_cast<BOARD_ITEM*>( eda_item )->IsLocked() )
171 group->SetLocked( true );
172 }
173 }
174
175 m_commit->Add( group );
176
177 for( EDA_ITEM* eda_item : selection )
178 {
179 if( eda_item->IsBOARD_ITEM() )
180 m_commit->Stage( static_cast<BOARD_ITEM*>( eda_item ), CHT_GROUP );
181 }
182
183 m_commit->Push( _( "Group Items" ) );
184
187
189 m_frame->OnModify();
190
191 return 0;
192}
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: actions.h:223
static TOOL_ACTION pickerTool
Definition: actions.h:249
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: actions.h:220
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:78
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:299
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:297
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:463
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:82
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:110
void DoAddMember(EDA_ITEM *aItem)
bool Show(bool show) override
FRAME_T GetFrameType() const
virtual void OnModify()
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:96
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:348
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:202
DIALOG_GROUP_PROPERTIES * m_propertiesDialog
Definition: group_tool.h:79
EDA_DRAW_FRAME * m_frame
Definition: group_tool.h:78
std::shared_ptr< COMMIT > m_commit
Definition: group_tool.h:81
int PickNewMember(const TOOL_EVENT &aEvent) override
Invoke the picker tool to select a new member of the group.
int Group(const TOOL_EVENT &aEvent) override
Ungroup selected items.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:53
Generic tool for picking an item.
The selection tool: currently supports:
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection, filtered according to aClientFilter.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:110
Extension of STATUS_POPUP for displaying a single line text.
Definition: status_popup.h:83
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
Generic, UI-independent tool event.
Definition: tool_event.h:168
void Activate()
Run the tool.
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
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
@ CHT_GROUP
Definition: commit.h:45
#define _(s)
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:43
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
Definition: wxgtk/ui.cpp:677
Class to handle a set of BOARD_ITEMs.