KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_setup_constraint_rules.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 PANEL_SETUP_CONSTRAINT_RULES_H
21#define PANEL_SETUP_CONSTRAINT_RULES_H
22
23#include <functional>
24#include <memory>
25#include <optional>
26#include <utility>
27#include <map>
28#include <vector>
29#include <wx/panel.h>
30#include <wx/timer.h>
31
35#include <widgets/unit_binder.h>
36
37class wxScrolledWindow;
38class wxStaticText;
39class wxTextCtrl;
40class BOARD;
44class NETCLASS;
45class NET_SETTINGS;
46class PCB_EDIT_FRAME;
47
48
51{
54
57};
58
59
60// MSVC sizes a member pointer by what it knows of the class, so BOARD_DESIGN_SETTINGS must be
61// complete here or this struct has a different layout in different files
71
72
82
83
89{
90 wxString title;
91 std::vector<CONSTRAINT_DEFAULT_FIELD> defaults;
92 std::optional<DRC_RULE_EDITOR_CONSTRAINT_NAME> ruleType;
93 std::function<std::optional<int>( const NETCLASS& )> netclassValue;
94
96 wxString settingsPage = wxEmptyString;
97
100};
101
102
103class PANEL_SETUP_CONSTRAINT_RULES : public wxPanel
104{
105public:
116
121 PANEL_SETUP_CONSTRAINT_RULES( wxWindow* aParent, PCB_EDIT_FRAME* aFrame, DRC_RULE_DOCUMENT* aDocument,
122 BOARD_DESIGN_SETTINGS& aSettings, const CONSTRAINT_SECTION& aSection );
123
127 static std::vector<CONSTRAINT_SECTION> SectionsFor( FAMILY aFamily );
128
130 static bool RulesCanOverride( const wxString& aSetting, DRC_CONSTRAINT_T* aConstraint );
131
133 static wxString PageTitleFor( DRC_RULE_EDITOR_CONSTRAINT_NAME aType );
134
136 static std::map<int, std::vector<wxString>> NetclassValuesFor( const wxString& aSetting,
137 const NET_SETTINGS& aNetSettings );
138
140 void ShowRule( DRC_RULE_EDITOR_CONSTRAINT_NAME aType, int aIndex );
141
143 static wxString PageEditingDefault( const wxString& aSetting );
144
151 static void LinkToPage( wxWindow* aField, const wxString& aPage, int aSlot = 1 );
152
159 static std::vector<std::pair<wxString, CONSTRAINT_DEFAULT_FIELD>> EditedDefaults();
160
165 void RefreshDefaults();
166
168 wxString ImportGroup() const;
169
170 void RefreshFromDocument();
171
172 bool TransferDataToWindow() override;
173
178 bool TransferDataFromWindow() override;
179
186 bool Validate() override;
187
188private:
190 static std::optional<CONSTRAINT_SECTION> sectionForSetting( const wxString& aSetting );
191
192 void buildSection();
193 void wrapLabels();
194 void showPage( const wxString& aTitle );
195
197 bool applyDefaults();
198
200 void writeDefaults( BOARD_DESIGN_SETTINGS& aSettings ) const;
201
203 void updateWarnings();
204
209 bool confirmPendingRule();
210
214 wxScrolledWindow* m_scrolled;
215
218 {
219 wxString settingName;
221 wxTextCtrl* ctrl;
223 std::unique_ptr<UNIT_BINDER> binder;
224
225
228 int loaded = 0;
229 };
230
232 std::vector<DEFAULT_FIELD> m_defaults;
233 wxStaticText* m_note;
234 wxString m_noteText;
235 wxStaticText* m_defaultsNote;
240};
241
242#endif // PANEL_SETUP_CONSTRAINT_RULES_H
Container for design settings for a BOARD object.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
The rules of one constraint type, in evaluation order, with an editor that opens in place.
The custom rules of one board, held in memory while Board Setup is open.
A warning icon drawn inside the right edge of a field, left of its dropdown button when it has one,...
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:44
NET_SETTINGS stores various net-related settings in a project context.
PANEL_SETUP_CONSTRAINT_RULES(wxWindow *aParent, PCB_EDIT_FRAME *aFrame, DRC_RULE_DOCUMENT *aDocument, BOARD_DESIGN_SETTINGS &aSettings, const CONSTRAINT_SECTION &aSection)
static wxString PageEditingDefault(const wxString &aSetting)
The title of the page that edits a board default, or empty where no rule page edits one.
std::vector< DEFAULT_FIELD > m_defaults
static std::vector< CONSTRAINT_SECTION > SectionsFor(FAMILY aFamily)
The sections of one family, in the order they are shown in the tree.
bool Validate() override
The rule form is always on screen, so its fields are empty until a rule is being written.
static bool RulesCanOverride(const wxString &aSetting, DRC_CONSTRAINT_T *aConstraint)
Whether rules can set a value other than this board default, and the DRC constraint that does it.
static wxString PageTitleFor(DRC_RULE_EDITOR_CONSTRAINT_NAME aType)
The title of the page that edits rules of this type, or empty when no page does.
static std::vector< std::pair< wxString, CONSTRAINT_DEFAULT_FIELD > > EditedDefaults()
Every board default a rule page edits, each with the group it is imported with.
bool TransferDataFromWindow() override
Called when the dialog is accepted.
void updateWarnings()
Shows a warning icon, with the reason as its tooltip, over each default whose value has an issue.
wxString ImportGroup() const
The Import Settings group this page's defaults travel with.
static std::map< int, std::vector< wxString > > NetclassValuesFor(const wxString &aSetting, const NET_SETTINGS &aNetSettings)
The net class values set for a constraint, grouped by value so equal classes list together.
bool confirmPendingRule()
Offers what to do with a rule the form holds.
void RefreshDefaults()
Reads the board defaults back into their fields, after something other than this page changed them.
void writeDefaults(BOARD_DESIGN_SETTINGS &aSettings) const
Copies the defaults this page edits into aSettings.
bool applyDefaults()
Writes the default fields to the board, or reports the first value out of range.
static void LinkToPage(wxWindow *aField, const wxString &aPage, int aSlot=1)
Puts a link to another page holding the same value at the field's right edge.
CONSTRAINT_RULES_LIST * m_list
Null until the section is built, and where a section carries no rules of its own.
void ShowRule(DRC_RULE_EDITOR_CONSTRAINT_NAME aType, int aIndex)
Opens one of this page's rules in its editor, when the page holds that rule type.
static std::optional< CONSTRAINT_SECTION > sectionForSetting(const wxString &aSetting)
The section whose board defaults include a setting, where one holds it.
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.
@ OPTIMUM
Asks for a value without raising the minimum, as a net class track width does.
@ MINIMUM
Raises the minimum, as a net class clearance does.
CONSTRAINT_VALUE
What a board default measures, which decides how its field is read and written.
@ LENGTH
A distance in board units, shown in the user's units.
int BOARD_DESIGN_SETTINGS::* member
One constraint on a Design Rules page: its board default, the net class values that apply to it,...
std::optional< DRC_RULE_EDITOR_CONSTRAINT_NAME > ruleType
std::vector< CONSTRAINT_DEFAULT_FIELD > defaults
std::function< std::optional< int >(const NETCLASS &)> netclassValue
wxString settingsPage
The group this section's defaults are imported with.
NETCLASS_CONSTRAINT_PART netclassPart
What a net class value does to this constraint, where a class can set one.
One board default, as this page shows it.
int loaded
The value as this page last read it, so an untouched field does not write back over an edit made to t...