KiCad PCB EDA Suite
drc_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) 2020-2022 KiCad Developers, see change_log.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 <pcb_edit_frame.h>
25#include <tool/tool_manager.h>
26#include <tools/pcb_actions.h>
27#include <tools/pcb_tool_base.h>
30#include <tools/drc_tool.h>
31#include <kiface_base.h>
32#include <dialog_drc.h>
33#include <board_commit.h>
35#include <progress_reporter.h>
36#include <drc/drc_engine.h>
37#include <drc/drc_item.h>
39
41 PCB_TOOL_BASE( "pcbnew.DRCTool" ),
42 m_editFrame( nullptr ),
43 m_pcb( nullptr ),
44 m_drcDialog( nullptr ),
45 m_drcRunning( false )
46{
47}
48
49
51{
52}
53
54
56{
57 m_editFrame = getEditFrame<PCB_EDIT_FRAME>();
58
59 if( m_pcb != m_editFrame->GetBoard() )
60 {
61 if( m_drcDialog )
63
66 }
67}
68
69
70void DRC_TOOL::ShowDRCDialog( wxWindow* aParent )
71{
72 bool show_dlg_modal = true;
73
74 // the dialog needs a parent frame. if it is not specified, this is the PCB editor frame
75 // specified in DRC_TOOL class.
76 if( !aParent )
77 {
78 // if any parent is specified, the dialog is modal.
79 // if this is the default PCB editor frame, it is not modal
80 show_dlg_modal = false;
81 aParent = m_editFrame;
82 }
83
84 Activate();
86
87 if( !m_drcDialog )
88 {
89 m_drcDialog = new DIALOG_DRC( m_editFrame, aParent );
91
92 if( show_dlg_modal )
93 m_drcDialog->ShowModal();
94 else
95 m_drcDialog->Show( true );
96 }
97 else // The dialog is just not visible (because the user has double clicked on an error item)
98 {
100 m_drcDialog->Show( true );
101 }
102}
103
104
106{
107 ShowDRCDialog( nullptr );
108 return 0;
109}
110
111
113{
114 if( m_drcDialog )
115 return m_drcDialog->IsShown();
116
117 return false;
118}
119
120
122{
123 if( m_drcDialog )
124 {
125 m_drcDialog->Destroy();
126 m_drcDialog = nullptr;
127 }
128}
129
130
131void DRC_TOOL::RunTests( PROGRESS_REPORTER* aProgressReporter, bool aRefillZones,
132 bool aReportAllTrackErrors, bool aTestFootprints )
133{
134 // One at a time, please.
135 // Note that the main GUI entry points to get here are blocked, so this is really an
136 // insurance policy and as such we make no attempts to queue up the DRC run or anything.
137 if( m_drcRunning )
138 return;
139
141 BOARD_COMMIT commit( m_editFrame );
143 bool netlistFetched = false;
144 wxWindowDisabler disabler( /* disable everything except: */ m_drcDialog );
145
146 m_drcRunning = true;
147
148 if( aRefillZones )
149 {
150 aProgressReporter->AdvancePhase( _( "Refilling all zones..." ) );
151
152 zoneFiller->FillAllZones( m_drcDialog, aProgressReporter );
153 }
154
155 m_drcEngine->SetDrawingSheet( m_editFrame->GetCanvas()->GetDrawingSheet() );
156
157 if( aTestFootprints && !Kiface().IsSingle() )
158 {
159 if( m_editFrame->FetchNetlistFromSchematic( netlist, _( "Schematic parity tests require a "
160 "fully annotated schematic." ) ) )
161 {
162 netlistFetched = true;
163 }
164
165 if( m_drcDialog )
166 m_drcDialog->Raise();
167
168 m_drcEngine->SetSchematicNetlist( &netlist );
169 }
170
171 m_drcEngine->SetProgressReporter( aProgressReporter );
172
173 m_drcEngine->SetViolationHandler(
174 [&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, int aLayer )
175 {
176 PCB_MARKER* marker = new PCB_MARKER( aItem, aPos, aLayer );
177 commit.Add( marker );
178 } );
179
180 m_drcEngine->RunTests( m_editFrame->GetUserUnits(), aReportAllTrackErrors, aTestFootprints );
181
182 m_drcEngine->SetProgressReporter( nullptr );
183 m_drcEngine->ClearViolationHandler();
184
185 if( m_drcDialog )
186 {
188
189 if( aTestFootprints && netlistFetched )
191 }
192
193 commit.Push( _( "DRC" ), SKIP_UNDO | SKIP_SET_DIRTY );
194
195 m_drcRunning = false;
196
198
199 // update the m_drcDialog listboxes
201}
202
203
205{
206 // update my pointers, m_editFrame is the only unchangeable one
208
210
211 if( m_drcDialog )
213}
214
215
217{
218 if( m_drcDialog )
219 {
220 m_drcDialog->Show( true );
221 m_drcDialog->Raise();
223 }
224 else
225 {
226 ShowDRCDialog( nullptr );
227 }
228
229 return 0;
230}
231
232
234{
235 if( m_drcDialog )
236 {
237 m_drcDialog->Show( true );
238 m_drcDialog->Raise();
240 }
241 else
242 {
243 ShowDRCDialog( nullptr );
244 }
245
246 return 0;
247}
248
249
251{
252 if( m_drcDialog )
253 {
255 PCB_SELECTION& selection = selectionTool->GetSelection();
256
257 if( selection.GetSize() == 1 && selection.Front()->Type() == PCB_MARKER_T )
258 {
259 if( !m_drcDialog->IsShown() )
260 m_drcDialog->Show( true );
261
262 m_drcDialog->SelectMarker( static_cast<PCB_MARKER*>( selection.Front() ) );
263 }
264 }
265
266 return 0;
267}
268
269
270void DRC_TOOL::CrossProbe( const PCB_MARKER* aMarker )
271{
272 if( !IsDRCDialogShown() )
273 ShowDRCDialog( nullptr );
274
275 m_drcDialog->SelectMarker( aMarker );
276}
277
278
280{
281 if( m_drcDialog )
283
284 return 0;
285}
286
287
289{
296}
297
298
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
#define SKIP_SET_DIRTY
Definition: board_commit.h:41
#define SKIP_UNDO
Definition: board_commit.h:39
static TOOL_ACTION excludeMarker
Definition: actions.h:90
static TOOL_ACTION nextMarker
Definition: actions.h:89
static TOOL_ACTION prevMarker
Definition: actions.h:88
std::shared_ptr< DRC_ENGINE > m_DRCEngine
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:704
void SetFootprintTestsRun()
Called after running Footprint Tests.
Definition: dialog_drc.h:61
void UpdateData()
Rebuild the contents of the violation tabs based on the current markers and severties.
Definition: dialog_drc.cpp:335
void SetDrcRun()
Called after running DRC.
Definition: dialog_drc.h:55
void SelectMarker(const PCB_MARKER *aMarker)
Definition: dialog_drc.cpp:960
void PrevMarker()
Definition: dialog_drc.cpp:930
void NextMarker()
Definition: dialog_drc.cpp:945
void ExcludeMarker()
Definition: dialog_drc.cpp:983
bool Show(bool show) override
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
Definition: drc_tool.cpp:55
void ShowDRCDialog(wxWindow *aParent)
Opens the DRC dialog.
Definition: drc_tool.cpp:70
int NextMarker(const TOOL_EVENT &aEvent)
Definition: drc_tool.cpp:233
DRC_TOOL()
Definition: drc_tool.cpp:40
void DestroyDRCDialog()
Close and free the DRC dialog.
Definition: drc_tool.cpp:121
DIALOG_DRC * m_drcDialog
Definition: drc_tool.h:112
PCB_EDIT_FRAME * m_editFrame
Definition: drc_tool.h:110
~DRC_TOOL()
Definition: drc_tool.cpp:50
bool IsDRCDialogShown()
Check to see if the DRC_TOOL dialog is currently shown.
Definition: drc_tool.cpp:112
int CrossProbe(const TOOL_EVENT &aEvent)
Definition: drc_tool.cpp:250
int ExcludeMarker(const TOOL_EVENT &aEvent)
Definition: drc_tool.cpp:279
void setTransitions() override
< Set up handlers for various events.
Definition: drc_tool.cpp:288
BOARD * m_pcb
Definition: drc_tool.h:111
int PrevMarker(const TOOL_EVENT &aEvent)
Definition: drc_tool.cpp:216
bool m_drcRunning
Definition: drc_tool.h:113
void RunTests(PROGRESS_REPORTER *aProgressReporter, bool aRefillZones, bool aReportAllTrackErrors, bool aTestFootprints)
Run the DRC tests.
Definition: drc_tool.cpp:131
void updatePointers()
Update needed pointers from the one pointer which is known not to change.
Definition: drc_tool.cpp:204
std::shared_ptr< DRC_ENGINE > m_drcEngine
Definition: drc_tool.h:114
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
static const TOOL_EVENT SelectedEvent
Definition: actions.h:207
static const TOOL_EVENT PointSelectedEvent
Definition: actions.h:206
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition: pcb_netlist.h:213
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
static TOOL_ACTION runDRC
Definition: pcb_actions.h:384
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
DS_PROXY_VIEW_ITEM * GetDrawingSheet() const
bool FetchNetlistFromSchematic(NETLIST &aNetlist, const wxString &aAnnotateMessage)
void ResolveDRCExclusions()
Update markers to match recorded exclusions.
The selection tool: currently supports:
PCB_SELECTION & GetSelection()
const PCB_SELECTION & selection() const
A progress reporter interface for use in multi-threaded environments.
virtual void AdvancePhase()=0
Use the next available virtual zone of the dialog progress bar.
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:99
EDA_ITEM * Front() const
Definition: selection.h:208
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:156
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).
void Activate()
Run the tool.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
EDA_UNITS GetUserUnits() const
Handle actions specific to filling copper zones.
void FillAllZones(wxWindow *aCaller, PROGRESS_REPORTER *aReporter=nullptr)
#define _(s)
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition: typeinfo.h:104