KiCad PCB EDA Suite
Loading...
Searching...
No Matches
via_stitch_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 */
20
21#include "via_stitch_tool.h"
22
23#include <board_commit.h>
24#include <pcb_track.h>
27#include <tool/tool_manager.h>
28#include <tool/tool_menu.h>
30#include <tools/pcb_actions.h>
32
33
35{
36 auto hasExclusionsCondition = []( const SELECTION& aSel )
37 {
38 for( EDA_ITEM* item : aSel )
39 {
40 if( PCB_VIA_STITCH* stitch = dynamic_cast<PCB_VIA_STITCH*>( item ) )
41 {
42 if( stitch->HasExclusions() )
43 return true;
44 }
45 }
46
47 return false;
48 };
49
50 if( PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>() )
51 {
52 CONDITIONAL_MENU& menu = selTool->GetToolMenu().GetMenu();
53
54 menu.AddItem( PCB_ACTIONS::clearStitchViaExclusions, hasExclusionsCondition, 100 );
55 }
56
57 return true;
58}
59
60
62{
63 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
64 const PCB_SELECTION& sel = selTool->GetSelection();
65
66 BOARD_COMMIT commit( this );
67 std::set<PCB_VIA_STITCH*> toRegenerate;
68
69 for( EDA_ITEM* item : sel )
70 {
71 if( item->Type() != PCB_VIA_T )
72 continue;
73
74 PCB_VIA* via = static_cast<PCB_VIA*>( item );
75 EDA_GROUP* parent = via->GetParentGroup();
76
77 if( !parent )
78 continue;
79
80 PCB_VIA_STITCH* stitch = dynamic_cast<PCB_VIA_STITCH*>( parent->AsEdaItem() );
81
82 if( !stitch )
83 continue;
84
85 if( commit.GetStatus( stitch ) != CHT_MODIFY )
86 commit.Modify( stitch );
87
88 stitch->ExcludePosition( via->GetPosition() );
89 toRegenerate.insert( stitch );
90 }
91
92 if( toRegenerate.empty() )
93 return 0;
94
95 selTool->ClearSelection();
96
97 GENERATOR_TOOL* genTool = m_toolMgr->GetTool<GENERATOR_TOOL>();
98
99 for( PCB_VIA_STITCH* stitch : toRegenerate )
100 {
101 stitch->EditStart( genTool, board(), &commit );
102 stitch->Update( genTool, board(), &commit );
103 stitch->EditFinish( genTool, board(), &commit );
104 }
105
106 commit.Push( _( "Exclude Via From Stitching" ) );
107 frame()->RefreshCanvas();
108 return 0;
109}
110
111
113{
114 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
115 const PCB_SELECTION& sel = selTool->GetSelection();
116
117 BOARD_COMMIT commit( this );
118 std::set<PCB_VIA_STITCH*> toRegenerate;
119
120 for( EDA_ITEM* item : sel )
121 {
122 PCB_VIA_STITCH* stitch = dynamic_cast<PCB_VIA_STITCH*>( item );
123
124 if( !stitch || !stitch->HasExclusions() )
125 continue;
126
127 if( commit.GetStatus( stitch ) != CHT_MODIFY )
128 commit.Modify( stitch );
129
130 stitch->ClearAllExclusions();
131 toRegenerate.insert( stitch );
132 }
133
134 if( toRegenerate.empty() )
135 return 0;
136
137 GENERATOR_TOOL* genTool = m_toolMgr->GetTool<GENERATOR_TOOL>();
138
139 for( PCB_VIA_STITCH* stitch : toRegenerate )
140 {
141 stitch->EditStart( genTool, board(), &commit );
142 stitch->Update( genTool, board(), &commit );
143 stitch->EditFinish( genTool, board(), &commit );
144 }
145
146 commit.Push( _( "Clear Via Stitching Exclusions" ) );
147 frame()->RefreshCanvas();
148 return 0;
149}
150
151
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
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:102
int GetStatus(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Returns status of an item.
Definition commit.cpp:232
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
virtual EDA_ITEM * AsEdaItem()=0
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
Handle actions specific to filling copper zones.
static TOOL_ACTION excludeStitchVia
Exclude selected stitching vias from their parent via-stitch generator.
static TOOL_ACTION clearStitchViaExclusions
Restore every manually-excluded via in the selected via-stitch generators.
The selection tool: currently supports:
int ClearSelection(const TOOL_EVENT &aEvent)
PCB_SELECTION & GetSelection()
T * frame() const
BOARD * board() const
void ClearAllExclusions()
Drop all manual exclusions.
bool HasExclusions() const
void ExcludePosition(const VECTOR2I &aPos)
Add a board position to the exclusion set so the next Update() skips it.
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
Generic, UI-independent tool event.
Definition tool_event.h:167
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).
int ClearStitchViaExclusions(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int ExcludeStitchVia(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
@ CHT_MODIFY
Definition commit.h:40
#define _(s)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89