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