KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_rule_editor_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) 2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <pcb_edit_frame.h>
21#include <tool/tool_manager.h>
22#include <tools/pcb_actions.h>
23#include <tools/pcb_tool_base.h>
27#include <kiface_base.h>
28#include <board_commit.h>
30#include <progress_reporter.h>
31#include <drc/drc_engine.h>
32#include <drc/drc_item.h>
33#include <macros.h>
35
36
38 PCB_TOOL_BASE( "pcbnew.DRETool" ), m_editFrame( nullptr ), m_pcb( nullptr ),
39 m_drcRuleEditorDlg( nullptr )
40{
41}
42
43
47
48
50{
52
53 if( m_pcb != m_editFrame->GetBoard() )
54 {
57
58 m_pcb = m_editFrame->GetBoard();
59 m_drcEngine = m_pcb->GetDesignSettings().m_DRCEngine;
60 }
61}
62
63
65{
67 return m_drcRuleEditorDlg->IsShownOnScreen();
68
69 return false;
70}
71
72
74{
75 // update my pointers, m_editFrame is the only unchangeable one
76 m_pcb = m_editFrame->GetBoard();
77
79 m_drcRuleEditorDlg->UpdateData();
80}
81
82
84{
85 if( !m_editFrame->GetBoard() )
86 return;
87
88 bool show_dlg_modal = true;
89
90 // the dialog needs a parent frame. if it is not specified, this is the PCB editor frame
91 // specified in DRC_RULE_EDITOR_TOOL class.
92 if( !aParent )
93 {
94 // if any parent is specified, the dialog is modal.
95 // if this is the default PCB editor frame, it is not modal
96 show_dlg_modal = false;
97 aParent = m_editFrame;
98 }
99
100 Activate();
102
103 // Check if the rules file changed on disk since the dialog was last loaded
105 {
106 wxFileName rulesFile( m_editFrame->GetBoard()->GetDesignRulesPath() );
107 wxDateTime currentModTime;
108
109 if( rulesFile.FileExists() )
110 currentModTime = rulesFile.GetModificationTime();
111
112 if( !currentModTime.IsValid() || currentModTime != m_lastRulesFileModTime )
114 }
115
116 if( !m_drcRuleEditorDlg )
117 {
120
121 wxFileName rulesFile( m_editFrame->GetBoard()->GetDesignRulesPath() );
122
123 if( rulesFile.FileExists() )
124 m_lastRulesFileModTime = rulesFile.GetModificationTime();
125
126 if( show_dlg_modal )
127 m_drcRuleEditorDlg->ShowModal();
128 else
129 m_drcRuleEditorDlg->Show( true );
130 }
131 else
132 {
133 // File unchanged, bring existing dialog to front
134 m_drcRuleEditorDlg->Show( true );
135 m_drcRuleEditorDlg->Raise();
136 }
137}
138
139
141{
142 ShowDRCRuleEditorDialog( nullptr );
143 return 0;
144}
145
146
148{
150 {
151 m_drcRuleEditorDlg->Destroy();
152 m_drcRuleEditorDlg = nullptr;
153 }
154}
155
156
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
std::shared_ptr< DRC_ENGINE > m_drcEngine
void updatePointers()
Update needed pointers from the one pointer which is known not to change.
void ShowDRCRuleEditorDialog(wxWindow *aParent)
Opens the DRC Rule Editor dialog.
bool IsDRCRuleEditorDialogShown()
Check to see if the DRC_TOOL dialog is currently shown.
PCB_EDIT_FRAME * m_editFrame
void DestroyDRCRuleEditorDialog()
Close and free the DRC dialog.
void setTransitions() override
< Set up handlers for various events.
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
DIALOG_DRC_RULE_EDITOR * m_drcRuleEditorDlg
static TOOL_ACTION drcRuleEditor
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
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.
This file contains miscellaneous commonly used macros and functions.