KiCad PCB EDA Suite
Loading...
Searching...
No Matches
global_edit_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 (C) 2019-2020 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 <footprint.h>
25#include <pcb_track.h>
26#include <zone.h>
27#include <zones.h>
28#include <tool/tool_manager.h>
29#include <tools/pcb_actions.h>
30#include <tools/edit_tool.h>
36#include <board_commit.h>
38#include <tools/pcb_actions.h>
40
41
43 PCB_TOOL_BASE( "pcbnew.GlobalEdit" ),
44 m_selectionTool( nullptr )
45{
46}
47
48
50{
51 if( aReason != RUN )
52 m_commit = std::make_unique<BOARD_COMMIT>( this );
53}
54
55
57{
58 // Find the selection tool, so they can cooperate
60
61 return true;
62}
63
64
66{
68 FOOTPRINT* footprint = nullptr;
69 bool updateMode = false;
70 bool currentMode = false;
71
72 if( aEvent.HasPosition() )
74
75 if( !selection.Empty() )
77
79 {
80 updateMode = true;
81 currentMode = true;
82 }
83 else if( aEvent.IsAction( &PCB_ACTIONS::updateFootprints ) )
84 {
85 updateMode = true;
86 currentMode = selection.CountType( PCB_FOOTPRINT_T ) > 0;
87 }
88 else if( aEvent.IsAction( &PCB_ACTIONS::changeFootprint ) )
89 {
90 updateMode = false;
91 currentMode = true;
92 }
93 else if( aEvent.IsAction( &PCB_ACTIONS::changeFootprints ) )
94 {
95 updateMode = false;
96 currentMode = selection.CountType( PCB_FOOTPRINT_T ) > 0;
97 }
98 else
99 {
100 wxFAIL_MSG( wxT( "ExchangeFootprints: unexpected action" ) );
101 }
102
103 // invoke the exchange dialog process
104 {
105 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
106 DIALOG_EXCHANGE_FOOTPRINTS dialog( editFrame, footprint, updateMode, currentMode );
107 dialog.ShowQuasiModal();
108 }
109
110 return 0;
111}
112
113
115 std::map<PCB_LAYER_ID, PCB_LAYER_ID>& aLayerMap )
116{
117 LSET originalLayers = aItem->GetLayerSet();
118 LSET newLayers;
119
120 for( PCB_LAYER_ID original : originalLayers.Seq() )
121 {
122 if( aLayerMap.count( original ) )
123 newLayers.set( aLayerMap[ original ] );
124 else
125 newLayers.set( original );
126 }
127
128 if( originalLayers.Seq() != newLayers.Seq() )
129 {
130 m_commit->Modify( aItem );
131 aItem->SetLayerSet( newLayers );
132 frame()->GetCanvas()->GetView()->Update( aItem, KIGFX::GEOMETRY );
133 return true;
134 }
135
136 return false;
137}
138
139
141{
142 std::map<PCB_LAYER_ID, PCB_LAYER_ID> layerMap;
143
144 DIALOG_SWAP_LAYERS dlg( frame(), layerMap );
145
146 if( dlg.ShowModal() != wxID_OK )
147 return 0;
148
149 bool hasChanges = false;
150
151 // Change tracks.
152 for( PCB_TRACK* segm : frame()->GetBoard()->Tracks() )
153 {
154 if( segm->Type() == PCB_VIA_T )
155 {
156 PCB_VIA* via = static_cast<PCB_VIA*>( segm );
157 PCB_LAYER_ID top_layer, bottom_layer;
158
159 if( via->GetViaType() == VIATYPE::THROUGH )
160 continue;
161
162 via->LayerPair( &top_layer, &bottom_layer );
163
164 if( layerMap[bottom_layer] != bottom_layer || layerMap[top_layer] != top_layer )
165 {
166 m_commit->Modify( via );
167 via->SetLayerPair( layerMap[top_layer], layerMap[bottom_layer] );
169 hasChanges = true;
170 }
171 }
172 else
173 {
174 hasChanges |= swapBoardItem( segm, layerMap );
175 }
176 }
177
178 for( BOARD_ITEM* zone : frame()->GetBoard()->Zones() )
179 hasChanges |= swapBoardItem( zone, layerMap );
180
181 for( BOARD_ITEM* drawing : frame()->GetBoard()->Drawings() )
182 hasChanges |= swapBoardItem( drawing, layerMap );
183
184 if( hasChanges )
185 {
186 frame()->OnModify();
187 m_commit->Push( wxT( "Swap Layers" ) );
188 frame()->GetCanvas()->Refresh();
189 }
190
191 return 0;
192}
193
194
196{
197 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
198 DIALOG_CLEANUP_TRACKS_AND_VIAS dlg( editFrame );
199
200 dlg.ShowModal();
201 return 0;
202}
203
204
206{
207 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
208 DIALOG_CLEANUP_GRAPHICS dlg( editFrame, false );
209
210 dlg.ShowModal();
211 return 0;
212}
213
214
216{
217 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
219 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
220 {
221 sTool->FilterCollectorForHierarchy( aCollector, true );
222 } );
223 DIALOG_UNUSED_PAD_LAYERS dlg( editFrame, selection, *m_commit );
224
225 dlg.ShowModal();
226
227 return 0;
228}
229
231{
232 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
233
234 BOARD_COMMIT commit( editFrame );
235 BOARD* board = editFrame->GetBoard();
236
237 for( ZONE* zone : board->Zones() )
238 commit.Modify( zone );
239
241 int dialogResult = InvokeZonesManager( editFrame, &zoneInfo );
242
243 if( dialogResult == wxID_CANCEL )
244 return 0;
245
246 wxBusyCursor dummy;
247
248 // Undraw old zone outlines
249 for( ZONE* zone : board->Zones() )
250 editFrame->GetCanvas()->GetView()->Update( zone );
251
252
254 commit.Push( _( "Modify zones properties with zone manager" ), SKIP_CONNECTIVITY );
255 editFrame->OnModify();
256
257 //rebuildConnectivity
259
260 if( TOOL_MANAGER* manger = GetManager() )
261 {
262 manger->PostEvent( EVENTS::ConnectivityChangedEvent );
263 }
264
265 editFrame->GetCanvas()->RedrawRatsnest();
266
267 if( dialogResult == ZONE_MANAGER_REPOUR )
268 {
269 if( TOOL_MANAGER* manger = GetManager() )
270 {
271 manger->PostAction( PCB_ACTIONS::zoneFillAll );
272 }
273 }
274
275 return 0;
276}
277
278
279
281{
286
288
297}
298
299
#define SKIP_CONNECTIVITY
Definition: board_commit.h:42
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
void SetDefaultZoneSettings(const ZONE_SETTINGS &aSettings)
ZONE_SETTINGS & GetDefaultZoneSettings()
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:231
virtual void SetLayerSet(LSET aLayers)
Definition: board_item.h:239
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
const ZONES & Zones() const
Definition: board.h:327
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition: board.cpp:180
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:797
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
int ShowQuasiModal()
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
static void FootprintFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
A selection filter which prunes the selection to contain only items of type #PCB_MODULE_T.
Definition: edit_tool.cpp:2827
static const TOOL_EVENT ConnectivityChangedEvent
Selected item had a property changed (except movement)
Definition: actions.h:264
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:206
int ZonesManager(const TOOL_EVENT &aEvent)
int EditTracksAndVias(const TOOL_EVENT &aEvent)
int CleanupGraphics(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
bool swapBoardItem(BOARD_ITEM *aItem, std::map< PCB_LAYER_ID, PCB_LAYER_ID > &aLayerMap)
Set up handlers for various events.
int ExchangeFootprints(const TOOL_EVENT &aEvent)
Invoke the dialog used to update or exchange the footprint definitions used for footprints.
std::unique_ptr< BOARD_COMMIT > m_commit
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int GlobalDeletions(const TOOL_EVENT &aEvent)
int CleanupTracksAndVias(const TOOL_EVENT &aEvent)
int SwapLayers(const TOOL_EVENT &aEvent)
int EditTeardrops(const TOOL_EVENT &aEvent)
PCB_SELECTION_TOOL * m_selectionTool
int RemoveUnusedPads(const TOOL_EVENT &aEvent)
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: pcb_view.cpp:75
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:418
static TOOL_ACTION editTracksAndVias
Definition: pcb_actions.h:407
static TOOL_ACTION swapLayers
Definition: pcb_actions.h:417
static TOOL_ACTION zonesManager
Definition: pcb_actions.h:441
static TOOL_ACTION zoneFillAll
Definition: pcb_actions.h:393
static TOOL_ACTION updateFootprint
Definition: pcb_actions.h:413
static TOOL_ACTION cleanupTracksAndVias
Definition: pcb_actions.h:411
static TOOL_ACTION editTextAndGraphics
Definition: pcb_actions.h:408
static TOOL_ACTION globalDeletions
Definition: pcb_actions.h:410
static TOOL_ACTION updateFootprints
Definition: pcb_actions.h:414
static TOOL_ACTION removeUnusedPads
Definition: pcb_actions.h:418
static TOOL_ACTION changeFootprints
Definition: pcb_actions.h:416
static TOOL_ACTION changeFootprint
Definition: pcb_actions.h:415
static TOOL_ACTION editTeardrops
Definition: pcb_actions.h:409
static TOOL_ACTION cleanupGraphics
Definition: pcb_actions.h:412
void OnModify() override
Must be called after a change in order to set the "modify" flag and update other data structures and ...
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void RedrawRatsnest()
Return the bounding box of the view that should be used if model is not valid.
The main frame for Pcbnew.
void OnModify() override
Must be called after a board change to set the modified flag.
The selection tool: currently supports:
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection, filtered according to aClientFilter.
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
PCB_SELECTION & GetSelection()
PCB_BASE_EDIT_FRAME * frame() const
BOARD * board() const
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() const
T * FirstOfKind() const
Definition: selection.h:224
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:109
size_t CountType(KICAD_T aType) const
Definition: selection.cpp:156
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:145
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
@ RUN
Tool is invoked after being inactive.
Definition: tool_base.h:79
Generic, UI-independent tool event.
Definition: tool_event.h:167
bool HasPosition() const
Definition: tool_event.h:256
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:82
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
Master controller class:
Definition: tool_manager.h:57
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:71
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
int InvokeZonesManager(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aZoneInfo)
Function InvokeZonesManager invokes up a modal dialog window for zones manager.
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ GEOMETRY
Position or shape has changed.
Definition: view_item.h:54
BOARD * GetBoard()
std::vector< FAB_LAYER_COLOR > dummy
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
#define ZONE_MANAGER_REPOUR
Definition: zones.h:44