KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_drc_rule_editor.h
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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PANEL_DRC_RULE_EDITOR_H
21#define PANEL_DRC_RULE_EDITOR_H
22
23#include <wx/wx.h>
24
25#include <lset.h>
26#include <lseq.h>
27#include <variant>
28
35
36
40
43{
44public:
45 PANEL_DRC_RULE_EDITOR( wxWindow* aParent, BOARD* aBoard,
46 DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType,
47 wxString* aConstraintTitle,
48 std::shared_ptr<DRC_RE_BASE_CONSTRAINT_DATA> aConstraintData );
49
50 ~PANEL_DRC_RULE_EDITOR() override;
51
52 bool TransferDataToWindow() override;
53
54 bool TransferDataFromWindow() override;
55
57
58 void SetSaveCallback( std::function<void( int aNodeId )> aCallBackSave )
59 {
60 m_callBackSave = aCallBackSave;
61 }
62
63 void SetRemoveCallback( std::function<void( int aNodeId )> aCallBackRemove )
64 {
65 m_callBackRemove = aCallBackRemove;
66 }
67
68 void SetCloseCallback( std::function<void( int aNodeId )> aCallBackClose )
69 {
70 m_callBackClose = aCallBackClose;
71 }
72
74 std::function<bool( int aNodeId, wxString aRuleName )> aCallbackRuleNameValidation )
75 {
76 m_callBackRuleNameValidation = aCallbackRuleNameValidation;
77 }
78
79 void SetShowMatchesCallBack( std::function<int( int aNodeId )> aCallBackShowMatches )
80 {
81 m_callBackShowMatches = aCallBackShowMatches;
82 }
83
85
87
89
90 bool ValidateInputs( int* aErrorCount, wxString* aValidationMessage ) override;
91
92 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override;
93
94 void OnEnterKey( wxCommandEvent& aEvent ) override;
95
96 void Save( wxCommandEvent& aEvent );
97
98 void Cancel( wxCommandEvent& aEvent );
99
100private:
102 const DRC_RULE_EDITOR_CONSTRAINT_NAME& aConstraintType );
103
104 wxString buildLayerClause() const;
105
111 void onSaveButtonClicked( wxCommandEvent& aEvent );
112
118 void onRemoveButtonClicked( wxCommandEvent& aEvent );
119
125 void onCloseButtonClicked( wxCommandEvent& aEvent );
126
132 void onScintillaCharAdded( wxStyledTextEvent& aEvent );
133
139 void onSyntaxHelp( wxHyperlinkEvent& aEvent ) override;
140
146 void onCheckSyntax( wxCommandEvent& aEvent ) override;
147
153 void onErrorLinkClicked( wxHtmlLinkEvent& aEvent ) override;
154
160 void onContextMenu( wxMouseEvent& aEvent ) override;
161
162 void onShowMatchesButtonClicked( wxCommandEvent& aEvent );
163
164private:
166 std::vector<PCB_LAYER_ID> getSelectedLayers();
167 wxString getSelectedLayerSource() const;
168 void setSelectedLayers( const std::vector<PCB_LAYER_ID>& aLayers,
169 const wxString& aLayerSource = wxEmptyString );
170
172 std::vector<int> m_validLayers;
178
179 std::unique_ptr<SCINTILLA_TRICKS> m_scintillaTricks;
181 std::vector<int> m_layerIDs; // PCB_LAYER_ID or DRC_LAYER_SELECTOR_ID
185 std::shared_ptr<DRC_RE_BASE_CONSTRAINT_DATA> m_constraintData;
187
188 std::function<void( int aNodeId )> m_callBackSave;
189 std::function<void( int aNodeId )> m_callBackRemove;
190 std::function<void( int aNodeId )> m_callBackClose;
191 std::function<bool( int aNodeId, wxString aRuleName )> m_callBackRuleNameValidation;
192 std::function<int( int aNodeId )> m_callBackShowMatches;
193
196 wxRegEx m_typeRegex;
208
210};
211
212#endif // PANEL_DRC_RULE_EDITOR_H
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
Container panel that manages multiple condition rows with boolean operators.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition lseq.h:47
PANEL_DRC_RULE_EDITOR_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > m_constraintData
void onCloseButtonClicked(wxCommandEvent &aEvent)
Handles the close button click event, invoking the close callback.
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
PANEL_DRC_RULE_EDITOR(wxWindow *aParent, BOARD *aBoard, DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType, wxString *aConstraintTitle, std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > aConstraintData)
void SetRuleNameValidationCallback(std::function< bool(int aNodeId, wxString aRuleName)> aCallbackRuleNameValidation)
void onScintillaCharAdded(wxStyledTextEvent &aEvent)
Handles character addition in the Scintilla text control, performing auto-complete and context-sensit...
void SetCloseCallback(std::function< void(int aNodeId)> aCallBackClose)
void onShowMatchesButtonClicked(wxCommandEvent &aEvent)
void SetSaveCallback(std::function< void(int aNodeId)> aCallBackSave)
void onCheckSyntax(wxCommandEvent &aEvent) override
Checks the syntax of the DRC rule condition and reports any errors.
std::function< void(int aNodeId)> m_callBackSave
HTML_MESSAGE_BOX * m_helpWindow
wxString getSelectedLayerSource() const
void onContextMenu(wxMouseEvent &aEvent) override
Handles right-click context menu actions for text editing (undo, redo, cut, copy, paste,...
void onRemoveButtonClicked(wxCommandEvent &aEvent)
Handles the remove button click event, invoking the remove callback.
void setSelectedLayers(const std::vector< PCB_LAYER_ID > &aLayers, const wxString &aLayerSource=wxEmptyString)
DRC_LAYER_CATEGORY m_layerCategory
std::function< bool(int aNodeId, wxString aRuleName)> m_callBackRuleNameValidation
void onSyntaxHelp(wxHyperlinkEvent &aEvent) override
Displays a modeless help window with syntax and rule documentation.
std::vector< int > m_layerIDs
void populateLayerSelector(DRC_LAYER_CATEGORY aCategory)
DRC_RULE_EDITOR_CONSTRAINT_NAME m_constraintType
void SetShowMatchesCallBack(std::function< int(int aNodeId)> aCallBackShowMatches)
void Cancel(wxCommandEvent &aEvent)
void onErrorLinkClicked(wxHtmlLinkEvent &aEvent) override
Handles clicks on error links in the syntax error report and navigates to the error location.
std::function< void(int aNodeId)> m_callBackRemove
void OnEnterKey(wxCommandEvent &aEvent) override
std::function< int(int aNodeId)> m_callBackShowMatches
DRC_RE_CONDITION_GROUP_PANEL * m_conditionGroupPanel
std::unique_ptr< SCINTILLA_TRICKS > m_scintillaTricks
void Save(wxCommandEvent &aEvent)
void onSaveButtonClicked(wxCommandEvent &aEvent)
Handles the save button click event, validating inputs and invoking the save callback if valid.
std::vector< int > m_validLayers
DRC_RULE_EDITOR_CONTENT_PANEL_BASE * getConstraintPanel(wxWindow *aParent, const DRC_RULE_EDITOR_CONSTRAINT_NAME &aConstraintType)
void SetRemoveCallback(std::function< void(int aNodeId)> aCallBackRemove)
std::vector< PCB_LAYER_ID > getSelectedLayers()
std::function< void(int aNodeId)> m_callBackClose
bool ValidateInputs(int *aErrorCount, wxString *aValidationMessage) override
DRC_RULE_EDITOR_CONTENT_PANEL_BASE * m_constraintPanel
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
DRC_RULE_EDITOR_CONSTRAINT_NAME
DRC_LAYER_CATEGORY
Layer categories for filtering the layer selector dropdown.