KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_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 <tool/actions.h>
24#include <frame_type.h>
25#include <eda_draw_frame.h>
26#include <symbol_edit_frame.h>
27#include <sch_edit_frame.h>
28#include <sch_screen.h>
29#include <kiplatform/ui.h>
30#include <tool/tool_manager.h>
31#include <tool/picker_tool.h>
34#include <status_popup.h>
35#include <sch_commit.h>
37#include <sch_group.h>
38#include <symbol.h>
39
40
42{
43 bool isSymbolEditor = m_frame->GetFrameType() == FRAME_SCH_SYMBOL_EDITOR;
46
47 STATUS_TEXT_POPUP statusPopup( m_frame );
48 bool done = false;
49
51 m_propertiesDialog->Show( false );
52
53 Activate();
54
55 statusPopup.SetText( _( "Click on new member..." ) );
56
57 picker->SetClickHandler(
58 [&]( const VECTOR2D& aPoint ) -> bool
59 {
61
62 const SCH_SELECTION& sel = selTool->RequestSelection();
63
64 if( sel.Empty() )
65 return true; // still looking for an item
66
67 statusPopup.Hide();
68
70 {
71 EDA_ITEM* elem = sel.Front();
72
73 if( !isSymbolEditor )
74 {
75 while( elem->GetParent() && elem->GetParent()->Type() != SCH_SCREEN_T )
76 elem = elem->GetParent();
77 }
78
80 m_propertiesDialog->Show( true );
81 }
82
83 return false; // got our item; don't need any more
84 } );
85
86 picker->SetMotionHandler(
87 [&]( const VECTOR2D& aPos )
88 {
89 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, -50 ) );
90 } );
91
92 picker->SetCancelHandler(
93 [&]()
94 {
95 if( m_propertiesDialog )
96 m_propertiesDialog->Show( true );
97
98 statusPopup.Hide();
99 } );
100
101 picker->SetFinalizeHandler(
102 [&]( const int& aFinalState )
103 {
104 done = true;
105 } );
106
107 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, -50 ) );
108 statusPopup.Popup();
109 m_frame->GetCanvas()->SetStatusPopup( statusPopup.GetPanel() );
110
111 m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
112
113 while( !done )
114 {
115 // Pass events unless we receive a null event, then we must shut down
116 if( TOOL_EVENT* evt = Wait() )
117 evt->SetPassEvent();
118 else
119 break;
120 }
121
122 m_frame->GetCanvas()->SetStatusPopup( nullptr );
123
124 return 0;
125}
126
127
129{
130 bool isSymbolEditor = m_frame->GetFrameType() == FRAME_SCH_SYMBOL_EDITOR;
132 SCH_SELECTION selection = selTool->RequestSelection();
133
134 // Iterate from the back so we don't have to worry about removals.
135 for( int ii = selection.GetSize() - 1; ii >= 0; --ii )
136 {
137 if( !selection[ii]->IsSCH_ITEM() )
138 {
139 selection.Remove( selection[ii] );
140 continue;
141 }
142
143 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( selection[ii] );
144
145 if( !schItem->IsGroupableType() )
146 selection.Remove( schItem );
147 }
148
149 if( selection.Empty() )
150 return 0;
151
153 SCH_SCREEN* screen = static_cast<SCH_BASE_FRAME*>( m_frame )->GetScreen();
154
155 if( isSymbolEditor )
156 group->SetParent( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol() );
157 else
158 group->SetParent( screen );
159
160 for( EDA_ITEM* eda_item : selection )
161 {
162 if( EDA_GROUP* existingGroup = eda_item->GetParentGroup() )
163 m_commit->Modify( existingGroup->AsEdaItem(), screen, RECURSE_MODE::NO_RECURSE );
164
165 m_commit->Modify( eda_item, screen, RECURSE_MODE::NO_RECURSE );
166 group->AddItem( eda_item );
167 }
168
169 m_commit->Add( group, screen );
170 m_commit->Push( _( "Group Items" ) );
171
174
176 m_frame->OnModify();
177
178 return 0;
179}
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: actions.h:220
static TOOL_ACTION pickerTool
Definition: actions.h:246
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: actions.h:217
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 set of EDA_ITEMs (i.e., without duplicates).
Definition: eda_group.h:46
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:97
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:345
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
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
int Group(const TOOL_EVENT &aEvent) override
Ungroup selected items.
int PickNewMember(const TOOL_EVENT &aEvent) override
Invoke the picker tool to select a new member of the group.
A set of SCH_ITEMs (i.e., without duplicates).
Definition: sch_group.h:52
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
bool IsGroupableType() const
Definition: sch_item.cpp:127
SCH_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, bool aPromoteCellSelections=false, bool aPromoteGroups=false)
Return either an existing selection (filtered), or the selection at the current cursor position if th...
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.cpp:60
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
The symbol library editor main window.
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
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
#define _(s)
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
Definition: wxgtk/ui.cpp:677
Class to handle a set of SCH_ITEMs.