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
17 * along with this program. If not, see <https://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, DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType,
46 std::shared_ptr<DRC_RE_BASE_CONSTRAINT_DATA> aConstraintData );
47
48 ~PANEL_DRC_RULE_EDITOR() override;
49
50 bool TransferDataToWindow() override;
51
52 bool TransferDataFromWindow() override;
53
55
56 bool IsModified() const { return m_modified; }
57
59 void ClearModified() { m_modified = false; }
60
62 bool ValidateRule();
63
64 void SetSaveCallback( std::function<void( int aNodeId )> aCallBackSave ) { m_callBackSave = aCallBackSave; }
65
67 std::function<bool( int aNodeId, const wxString& aRuleName )> aCallbackRuleNameValidation )
68 {
69 m_callBackRuleNameValidation = aCallbackRuleNameValidation;
70 }
71
73 void SetFieldChangeCallback( std::function<void()> aCallback ) { m_callBackFieldChanged = aCallback; }
74
76 wxString GetCondition() const;
77
79 wxString GetLayerSource() const { return getSelectedLayerSource(); }
80
81 void SetShowMatchesCallBack( std::function<int( int aNodeId )> aCallBackShowMatches )
82 {
83 m_callBackShowMatches = aCallBackShowMatches;
84 }
85
89 static PANEL_DRC_RULE_EDITOR* FindEditor( wxWindow* aChild );
90
92 void RelayoutHost() { LayoutAncestors( this ); }
93
95 static void LayoutAncestors( wxWindow* aWindow );
96
98 void SetOverrideNote( const wxString& aText );
99
101
103
104 bool ValidateInputs( int* aErrorCount, wxString* aValidationMessage ) override;
105
106 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override;
107
108 void OnEnterKey( wxCommandEvent& aEvent ) override;
109
110 void Save( wxCommandEvent& aEvent );
111
112private:
114 const DRC_RULE_EDITOR_CONSTRAINT_NAME& aConstraintType );
115
116 wxString buildLayerClause() const;
117
118 void onFieldChanged( wxEvent& aEvent );
119
120 void clearMatchReport();
121
122
124
125 wxStaticText* m_overrideNote = nullptr;
126
132 void onSaveButtonClicked( wxCommandEvent& aEvent );
133
140 void onScintillaCharAdded( wxStyledTextEvent& aEvent );
141
147 void onSyntaxHelp( wxHyperlinkEvent& aEvent ) override;
148
154 void onCheckSyntax( wxCommandEvent& aEvent ) override;
155
161 void onErrorLinkClicked( wxHtmlLinkEvent& aEvent ) override;
162
169 void onContextMenu( wxMouseEvent& aEvent ) override;
170
171 void onShowMatchesButtonClicked( wxCommandEvent& aEvent );
172
173private:
175 std::vector<PCB_LAYER_ID> getSelectedLayers();
176 wxString getSelectedLayerSource() const;
177 void setSelectedLayers( const std::vector<PCB_LAYER_ID>& aLayers,
178 const wxString& aLayerSource = wxEmptyString );
179
181 wxStaticText* m_matchReport;
182 std::vector<int> m_validLayers;
188
189 std::unique_ptr<SCINTILLA_TRICKS> m_scintillaTricks;
191 std::vector<int> m_layerIDs; // PCB_LAYER_ID or DRC_LAYER_SELECTOR_ID
195 std::shared_ptr<DRC_RE_BASE_CONSTRAINT_DATA> m_constraintData;
197
198 std::function<void( int aNodeId )> m_callBackSave;
199 std::function<bool( int aNodeId, const wxString& aRuleName )> m_callBackRuleNameValidation;
200 std::function<int( int aNodeId )> m_callBackShowMatches;
201 std::function<void()> m_callBackFieldChanged;
202
204};
205
206#endif // PANEL_DRC_RULE_EDITOR_H
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
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=wxBORDER_NONE|wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > m_constraintData
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
void onScintillaCharAdded(wxStyledTextEvent &aEvent)
Handles character addition in the Scintilla text control, performing auto-complete and context-sensit...
static void LayoutAncestors(wxWindow *aWindow)
Lays out aWindow's parents, out to the page it scrolls in.
void onShowMatchesButtonClicked(wxCommandEvent &aEvent)
void ClearModified()
Called once the form's contents have reached the document.
void onFieldChanged(wxEvent &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
static PANEL_DRC_RULE_EDITOR * FindEditor(wxWindow *aChild)
The rule editor that hosts aChild, or nullptr when it is not inside one.
wxString getSelectedLayerSource() const
void onContextMenu(wxMouseEvent &aEvent) override
Handles right-click context menu actions for text editing (undo, redo, cut, copy, paste,...
PANEL_DRC_RULE_EDITOR(wxWindow *aParent, BOARD *aBoard, DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType, std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > aConstraintData)
wxString GetCondition() const
The condition the form currently describes, which is not yet the one the rule applies.
std::function< void()> m_callBackFieldChanged
void setSelectedLayers(const std::vector< PCB_LAYER_ID > &aLayers, const wxString &aLayerSource=wxEmptyString)
DRC_LAYER_CATEGORY m_layerCategory
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 SetOverrideNote(const wxString &aText)
Shows a line above the constraint saying what this rule displaces, or clears it when empty.
void SetShowMatchesCallBack(std::function< int(int aNodeId)> aCallBackShowMatches)
void SetRuleNameValidationCallback(std::function< bool(int aNodeId, const wxString &aRuleName)> aCallbackRuleNameValidation)
void RelayoutHost()
Lays out the editor's parents, out to the page it scrolls in.
void onErrorLinkClicked(wxHtmlLinkEvent &aEvent) override
Handles clicks on error links in the syntax error report and navigates to the error location.
void OnEnterKey(wxCommandEvent &aEvent) override
std::function< int(int aNodeId)> m_callBackShowMatches
wxString GetLayerSource() const
The layers the form currently selects, empty for any layer.
std::function< bool(int aNodeId, const wxString &aRuleName)> m_callBackRuleNameValidation
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)
std::vector< PCB_LAYER_ID > getSelectedLayers()
bool ValidateRule()
Runs the rule's validators and keeps the outcome, without applying anything.
bool ValidateInputs(int *aErrorCount, wxString *aValidationMessage) override
DRC_RULE_EDITOR_CONTENT_PANEL_BASE * m_constraintPanel
void SetFieldChangeCallback(std::function< void()> aCallback)
Called whenever a field is edited, so a caller can follow the form rather than the document.
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.