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 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
25#include <footprint.h>
26#include <pcb_track.h>
27#include <pcb_generator.h>
28#include <tool/tool_manager.h>
29#include <tools/pcb_actions.h>
30#include <tools/edit_tool.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 PCB_SELECTION& selection = m_selectionTool->GetSelection();
69 FOOTPRINT* footprint = nullptr;
70 bool updateMode = false;
71 bool currentMode = false;
72
73 if( aEvent.HasPosition() )
74 selection = m_selectionTool->RequestSelection( EDIT_TOOL::FootprintFilter );
75
76 if( !selection.Empty() )
77 footprint = selection.FirstOfKind<FOOTPRINT>();
78
80 {
81 updateMode = true;
82 currentMode = true;
83 }
84 else if( aEvent.IsAction( &PCB_ACTIONS::updateFootprints ) )
85 {
86 updateMode = true;
87 currentMode = selection.CountType( PCB_FOOTPRINT_T ) > 0;
88 }
89 else if( aEvent.IsAction( &PCB_ACTIONS::changeFootprint ) )
90 {
91 updateMode = false;
92 currentMode = true;
93 }
94 else if( aEvent.IsAction( &PCB_ACTIONS::changeFootprints ) )
95 {
96 updateMode = false;
97 currentMode = selection.CountType( PCB_FOOTPRINT_T ) > 0;
98 }
99 else
100 {
101 wxFAIL_MSG( wxT( "ExchangeFootprints: unexpected action" ) );
102 }
103
104 DIALOG_EXCHANGE_FOOTPRINTS dialog( editFrame, footprint, updateMode, currentMode );
105 dialog.ShowQuasiModal();
106
107 return 0;
108}
109
110
111bool GLOBAL_EDIT_TOOL::swapBoardItem( BOARD_ITEM* aItem, std::map<PCB_LAYER_ID, PCB_LAYER_ID>& aLayerMap )
112{
113 LSET originalLayers = aItem->GetLayerSet();
114 LSET newLayers;
115
116 for( PCB_LAYER_ID original : originalLayers )
117 {
118 if( aLayerMap.count( original ) )
119 newLayers.set( aLayerMap[ original ] );
120 else
121 newLayers.set( original );
122 }
123
124 if( originalLayers != newLayers )
125 {
126 m_commit->Modify( aItem );
127 aItem->SetLayerSet( newLayers );
128 frame()->GetCanvas()->GetView()->Update( aItem, KIGFX::GEOMETRY );
129 return true;
130 }
131
132 return false;
133}
134
135
137{
138 std::map<PCB_LAYER_ID, PCB_LAYER_ID> layerMap;
139
140 DIALOG_SWAP_LAYERS dlg( frame(), layerMap );
141
142 if( dlg.ShowModal() != wxID_OK )
143 return 0;
144
145 bool hasChanges = false;
146
147 // Change tracks.
148 for( PCB_TRACK* segm : frame()->GetBoard()->Tracks() )
149 {
150 if( segm->Type() == PCB_VIA_T )
151 {
152 PCB_VIA* via = static_cast<PCB_VIA*>( segm );
153 PCB_LAYER_ID top_layer, bottom_layer;
154
155 if( via->GetViaType() == VIATYPE::THROUGH )
156 continue;
157
158 via->LayerPair( &top_layer, &bottom_layer );
159
160 if( layerMap[bottom_layer] != bottom_layer || layerMap[top_layer] != top_layer )
161 {
162 m_commit->Modify( via );
163 via->SetLayerPair( layerMap[top_layer], layerMap[bottom_layer] );
164 frame()->GetCanvas()->GetView()->Update( via, KIGFX::GEOMETRY );
165 hasChanges = true;
166 }
167 }
168 else
169 {
170 hasChanges |= swapBoardItem( segm, layerMap );
171 }
172 }
173
174 for( PCB_GENERATOR* generator : frame()->GetBoard()->Generators() )
175 hasChanges |= swapBoardItem( generator, layerMap );
176
177 for( BOARD_ITEM* zone : frame()->GetBoard()->Zones() )
178 hasChanges |= swapBoardItem( zone, layerMap );
179
180 for( BOARD_ITEM* drawing : frame()->GetBoard()->Drawings() )
181 hasChanges |= swapBoardItem( drawing, layerMap );
182
183 if( hasChanges )
184 {
185 frame()->OnModify();
186 m_commit->Push( _( "Swap Layers" ) );
187 frame()->GetCanvas()->Refresh();
188 }
189
190 return 0;
191}
192
193
195{
197 DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS dlg( editFrame );
198
199 dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
200 return 0;
201}
202
203
205{
207 DIALOG_CLEANUP_TRACKS_AND_VIAS dlg( editFrame );
208
209 dlg.ShowModal();
210 return 0;
211}
212
213
215{
217 DIALOG_CLEANUP_GRAPHICS dlg( editFrame, false );
218
219 dlg.ShowModal();
220 return 0;
221}
222
223
225{
227 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
228 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
229 {
230 sTool->FilterCollectorForHierarchy( aCollector, true );
231 } );
232 DIALOG_UNUSED_PAD_LAYERS dlg( editFrame, selection, *m_commit );
233
234 dlg.ShowModal();
235
236 return 0;
237}
238
240{
242 BOARD_COMMIT commit( editFrame );
243 BOARD* board = editFrame->GetBoard();
244
245 for( ZONE* zone : board->Zones() )
246 commit.Modify( zone );
247
248 ZONE_SETTINGS zoneInfo = board->GetDesignSettings().GetDefaultZoneSettings();
249 DIALOG_ZONE_MANAGER dlg( editFrame, &zoneInfo );
250
251 int dialogResult = dlg.ShowQuasiModal();
252
253 if( dialogResult == wxID_OK && ZONE_MANAGER_PREFERENCE::GetRepourOnClose() )
254 dialogResult = ZONE_MANAGER_REPOUR;
255
256 if( dialogResult == wxID_CANCEL )
257 return 0;
258
259 // Ensure all zones are deselected before make any change in view, to avoid
260 // dangling pointers in EDIT_POINT
262 selTool->ClearSelection();
263
264 wxBusyCursor dummy;
265
266 // Undraw old zone outlines
267 for( ZONE* zone : board->Zones() )
268 editFrame->GetCanvas()->GetView()->Update( zone );
269
271 board->GetDesignSettings().SetDefaultZoneSettings( zoneInfo );
272 commit.Push( _( "Modify zones properties with zone manager" ), SKIP_CONNECTIVITY );
273 editFrame->OnModify();
274
275 //rebuildConnectivity
276 board->BuildConnectivity();
277
278 if( TOOL_MANAGER* manger = GetManager() )
279 manger->PostEvent( EVENTS::ConnectivityChangedEvent );
280
281 editFrame->GetCanvas()->RedrawRatsnest();
282
283 if( dialogResult == ZONE_MANAGER_REPOUR )
284 {
285 if( TOOL_MANAGER* manger = GetManager() )
286 manger->PostAction( PCB_ACTIONS::zoneFillAll );
287 }
288
289 return 0;
290}
291
292
293
312
313
#define SKIP_CONNECTIVITY
BASE_SET & set(size_t pos)
Definition base_set.h:116
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:79
virtual void SetLayerSet(const LSET &aLayers)
Definition board_item.h:260
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:252
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:317
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:106
int ShowModal() override
static const TOOL_EVENT ConnectivityChangedEvent
Selected item had a property changed (except movement)
Definition actions.h:350
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:207
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:91
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition netinfo.h:369
static TOOL_ACTION editTracksAndVias
static TOOL_ACTION swapLayers
static TOOL_ACTION zonesManager
static TOOL_ACTION zoneFillAll
static TOOL_ACTION updateFootprint
static TOOL_ACTION cleanupTracksAndVias
static TOOL_ACTION editTextAndGraphics
static TOOL_ACTION globalDeletions
static TOOL_ACTION updateFootprints
static TOOL_ACTION removeUnusedPads
static TOOL_ACTION changeFootprints
static TOOL_ACTION changeFootprint
static TOOL_ACTION editTeardrops
static TOOL_ACTION cleanupGraphics
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:
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.
int ClearSelection(const TOOL_EVENT &aEvent)
T * frame() const
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
BOARD * board() const
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() const
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition tool_base.h:146
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:186
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
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:171
bool HasPosition() const
Returns if it this event has a valid position (true for mouse events and context-menu or hotkey-based...
Definition tool_event.h:260
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
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).
friend class TOOL_MANAGER
ZONE_SETTINGS handles zones parameters.
Handle a list of polygons defining a copper zone.
Definition zone.h:74
#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:55
@ THROUGH
Definition pcb_track.h:67
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
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
#define ZONE_MANAGER_REPOUR
Definition zones.h:44