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
88 std::string GetValidationMessage() { return m_validationMessage; }
89
90 bool ValidateInputs( int* aErrorCount, std::string* aValidationMessage ) override;
91
92 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override;
93
94 void Save( wxCommandEvent& aEvent );
95
96 void Cancel( wxCommandEvent& aEvent );
97
98private:
100 const DRC_RULE_EDITOR_CONSTRAINT_NAME& aConstraintType );
101
102 wxString buildLayerClause() const;
103
109 void onSaveButtonClicked( wxCommandEvent& aEvent );
110
116 void onRemoveButtonClicked( wxCommandEvent& aEvent );
117
123 void onCloseButtonClicked( wxCommandEvent& aEvent );
124
130 void onScintillaCharAdded( wxStyledTextEvent& aEvent );
131
137 void onSyntaxHelp( wxHyperlinkEvent& aEvent ) override;
138
144 void onCheckSyntax( wxCommandEvent& aEvent ) override;
145
151 void onErrorLinkClicked( wxHtmlLinkEvent& aEvent ) override;
152
158 void onContextMenu( wxMouseEvent& aEvent ) override;
159
160 void onShowMatchesButtonClicked( wxCommandEvent& aEvent );
161
162private:
163 std::vector<PCB_LAYER_ID> getSelectedLayers();
164 void setSelectedLayers( const std::vector<PCB_LAYER_ID>& aLayers );
165
167 std::vector<int> m_validLayers;
173
174 std::unique_ptr<SCINTILLA_TRICKS> m_scintillaTricks;
176 std::vector<PCB_LAYER_ID> m_layerIDs;
178 std::shared_ptr<DRC_RE_BASE_CONSTRAINT_DATA> m_constraintData;
180
181 std::function<void( int aNodeId )> m_callBackSave;
182 std::function<void( int aNodeId )> m_callBackRemove;
183 std::function<void( int aNodeId )> m_callBackClose;
184 std::function<bool( int aNodeId, wxString aRuleName )> m_callBackRuleNameValidation;
185 std::function<int( int aNodeId )> m_callBackShowMatches;
186
189 wxRegEx m_typeRegex;
201
203};
204
205#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
bool ValidateInputs(int *aErrorCount, std::string *aValidationMessage) override
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.
std::function< bool(int aNodeId, wxString aRuleName)> m_callBackRuleNameValidation
void onSyntaxHelp(wxHyperlinkEvent &aEvent) override
Displays a modeless help window with syntax and rule documentation.
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
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)
std::vector< PCB_LAYER_ID > m_layerIDs
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 setSelectedLayers(const std::vector< PCB_LAYER_ID > &aLayers)
void SetRemoveCallback(std::function< void(int aNodeId)> aCallBackRemove)
std::vector< PCB_LAYER_ID > getSelectedLayers()
std::function< void(int aNodeId)> m_callBackClose
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