KiCad PCB EDA Suite
Loading...
Searching...
No Matches
constraint_rules_list.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 The 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 CONSTRAINT_RULES_LIST_H
21#define CONSTRAINT_RULES_LIST_H
22
23#include <functional>
24#include <memory>
25#include <utility>
26#include <vector>
27
28#include <optional>
29
31
34
35class BOARD;
38class NETCLASS;
40class PCB_EDIT_FRAME;
41class UNITS_PROVIDER;
43
50{
51public:
52 CONSTRAINT_RULES_LIST( wxWindow* aParent, PCB_EDIT_FRAME* aFrame, DRC_RULE_DOCUMENT* aDocument,
53 DRC_RULE_EDITOR_CONSTRAINT_NAME aType, const wxString& aTitle );
54
55 void RefreshRules();
56
63 void SetNetclasses( std::function<std::optional<int>( const NETCLASS& )> aValue, NETCLASS_CONSTRAINT_PART aPart );
64
68 void SetTitleWindow( wxWindow* aWindow ) { m_titleWindow = aWindow; }
69
71 void SetDefaults( std::vector<std::pair<wxString, std::function<wxString()>>> aDefaults )
72 {
73 m_defaults = std::move( aDefaults );
74 }
75
78
82 bool HasPendingRule() const;
83
88 bool ApplyPendingRule();
89
93 void DiscardPendingRule();
94
99 bool ConfirmPendingRule();
100
102 bool EditRule( int aIndex );
103
108 void SetChangeCallback( std::function<void()> aCallback ) { m_onChanged = std::move( aCallback ); }
109
112 UNITS_PROVIDER* aUnits );
113
114private:
115 void onPrimary( wxCommandEvent& aEvent );
116 void onNewRule( wxCommandEvent& aEvent );
117 void onMoveUp( wxCommandEvent& aEvent );
118 void onMoveDown( wxCommandEvent& aEvent );
119 void onDuplicate( wxCommandEvent& aEvent );
120 void onRemove( wxCommandEvent& aEvent );
121
122 void moveSelected( int aDelta );
123
125 static void copyRuleData( DRC_RE_BASE_CONSTRAINT_DATA& aTarget, const DRC_RE_BASE_CONSTRAINT_DATA& aSource );
126
127 void buildEditor( const std::shared_ptr<DRC_RE_BASE_CONSTRAINT_DATA>& aData,
129 void showNewRule();
130 void showRule( int aIndex );
131 void addRule();
132 void applyRule();
133 int indexOf( const std::shared_ptr<DRC_RE_BASE_CONSTRAINT_DATA>& aData ) const;
134 int editingIndex() const;
135 void notifyChanged();
136 int showMatches();
137
138 int selectedIndex() const;
139 void selectIndex( int aIndex );
140 void updateButtons();
141 void relayout();
142 void reportError( const wxString& aMessage );
143
144 void fitColumns();
145
146 void showOverrideNote();
147
149 int addNetclassRows();
150
151 static wxString layersText( const DRC_RE_LOADED_PANEL_ENTRY& aEntry );
152 static wxString severityText( const DRC_RE_LOADED_PANEL_ENTRY& aEntry );
153 static wxString inUserUnits( const wxString& aClause, UNITS_PROVIDER* aUnits );
154 wxString sharedWithText( int aIndex ) const;
155
159 wxString m_title;
160 wxWindow* m_titleWindow;
161 std::vector<std::pair<wxString, std::function<wxString()>>> m_defaults;
162
164 std::shared_ptr<DRC_RE_BASE_CONSTRAINT_DATA> m_editingData;
166 std::function<void()> m_onChanged;
167 bool m_refreshing = false;
169
170 std::function<std::optional<int>( const NETCLASS& )> m_netclassValue;
172
174 std::vector<int> m_rowToIndex;
175
177 static constexpr int NETCLASS_ROW = -1;
178};
179
180#endif // CONSTRAINT_RULES_LIST_H
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
CONSTRAINT_RULES_LIST_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)
bool ConfirmPendingRule()
Asks what to do with a rule left in the form.
std::function< void()> m_onChanged
void RefreshOverrideNote()
Rebuilds the line saying what the rule being edited displaces.
wxString sharedWithText(int aIndex) const
bool EditRule(int aIndex)
Selects a rule and opens it in the editor. False if a rule left in the form kept it closed.
static wxString inUserUnits(const wxString &aClause, UNITS_PROVIDER *aUnits)
void onDuplicate(wxCommandEvent &aEvent)
static wxString ConstraintText(const DRC_RE_LOADED_PANEL_ENTRY &aEntry, DRC_RULE_EDITOR_CONSTRAINT_NAME aType, UNITS_PROVIDER *aUnits)
The constraint a rule sets, written the way the rule table shows it.
int addNetclassRows()
Fills the leading rows with the net class values, and returns how many it added.
std::vector< int > m_rowToIndex
The document index each row shows, or NETCLASS_ROW where the row is a net class value.
void onNewRule(wxCommandEvent &aEvent)
bool ApplyPendingRule()
Adds or updates the rule the form holds.
NETCLASS_CONSTRAINT_PART m_netclassPart
void buildEditor(const std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > &aData, DRC_RULE_EDITOR_CONSTRAINT_NAME aPanelType)
static constexpr int NETCLASS_ROW
What m_rowToIndex holds for a row that is not a rule of this document.
bool HasPendingRule() const
True while the form holds typing that has not been added to the list.
void onRemove(wxCommandEvent &aEvent)
void SetDefaults(std::vector< std::pair< wxString, std::function< wxString()> > > aDefaults)
The board defaults this constraint falls back to, each with the name the note gives it.
int indexOf(const std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > &aData) const
static void copyRuleData(DRC_RE_BASE_CONSTRAINT_DATA &aTarget, const DRC_RE_BASE_CONSTRAINT_DATA &aSource)
Copies everything the form edits, the rule name included.
void onMoveUp(wxCommandEvent &aEvent)
DRC_RULE_DOCUMENT * m_document
std::function< std::optional< int >(const NETCLASS &)> m_netclassValue
void SetNetclasses(std::function< std::optional< int >(const NETCLASS &)> aValue, NETCLASS_CONSTRAINT_PART aPart)
Lists the net class values for this constraint above the rules, where a class can set one.
std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > m_editingData
DRC_RULE_EDITOR_CONSTRAINT_NAME m_editingType
void SetChangeCallback(std::function< void()> aCallback)
Called after this list changed the document.
static wxString layersText(const DRC_RE_LOADED_PANEL_ENTRY &aEntry)
DRC_RULE_EDITOR_CONSTRAINT_NAME m_type
CONSTRAINT_RULES_LIST(wxWindow *aParent, PCB_EDIT_FRAME *aFrame, DRC_RULE_DOCUMENT *aDocument, DRC_RULE_EDITOR_CONSTRAINT_NAME aType, const wxString &aTitle)
PANEL_DRC_RULE_EDITOR * m_editor
std::vector< std::pair< wxString, std::function< wxString()> > > m_defaults
void onPrimary(wxCommandEvent &aEvent)
void reportError(const wxString &aMessage)
void SetTitleWindow(wxWindow *aWindow)
A window whose label is the section title.
void DiscardPendingRule()
Reloads the form from the document, dropping whatever was typed.
void onMoveDown(wxCommandEvent &aEvent)
static wxString severityText(const DRC_RE_LOADED_PANEL_ENTRY &aEntry)
The custom rules of one board, held in memory while Board Setup is open.
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:44
The main frame for Pcbnew.
DRC_RULE_EDITOR_CONSTRAINT_NAME
NETCLASS_CONSTRAINT_PART
What a net class value does to a constraint, which is not always raise its minimum.
@ MINIMUM
Raises the minimum, as a net class clearance does.
Represents a rule loaded from a .kicad_dru file and mapped to a panel.