KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_rule_document.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 DRC_RULE_DOCUMENT_H
21#define DRC_RULE_DOCUMENT_H
22
23#include <set>
24#include <vector>
25#include <wx/string.h>
26
28
29#include "drc_re_loaded_rule.h"
31
32class BOARD;
33
34
42{
43public:
44 DRC_RULE_DOCUMENT( BOARD* aBoard );
45
49 void Load();
50
55 void LoadFrom( const wxString& aPath );
56
60 bool Save( wxString* aError );
61
66 wxString GetText() const;
67
72 void SetText( const wxString& aText );
73
74 std::vector<DRC_RE_LOADED_PANEL_ENTRY>& Entries() { return m_entries; }
75
76 std::vector<int> IndicesFor( DRC_RULE_EDITOR_CONSTRAINT_NAME aType ) const;
77
79 std::vector<int> IndicesSetting( DRC_CONSTRAINT_T aConstraint ) const;
80
81 int Add( const DRC_RE_LOADED_PANEL_ENTRY& aEntry );
82
87 void UpdateEntry( int aIndex, const DRC_RE_LOADED_PANEL_ENTRY& aEdited );
88
89 void Remove( int aIndex );
90
91 int Duplicate( int aIndex );
92
97 bool Move( int aIndex, int aDelta, DRC_RULE_EDITOR_CONSTRAINT_NAME aType );
98
99 bool IsRuleNameUnique( const wxString& aName, DRC_RULE_EDITOR_CONSTRAINT_NAME aType, int aExceptIndex ) const;
100
101 wxString UniqueRuleName( const wxString& aBase ) const;
102
103 int NextId() { return m_nextId++; }
104
105 bool IsModified() const { return m_modified; }
106
111 bool HasUnparsedText() const { return m_hasRawText; }
112
117 static size_t FindConstraintClause( const wxString& aText, const wxString& aCode );
118
120 static std::set<DRC_CONSTRAINT_T> ConstraintsOf( const DRC_RE_LOADED_PANEL_ENTRY& aEntry );
121
122private:
124 bool load( const wxString& aPath );
125
126 bool parseInto( const wxString& aText );
127
128 void prepareEntries();
129
130 void touch();
131
133 std::vector<DRC_RE_LOADED_PANEL_ENTRY> m_entries;
135 wxString m_rawText;
141};
142
143#endif // DRC_RULE_DOCUMENT_H
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
bool HasUnparsedText() const
True while the Custom Rules text could not be parsed.
std::vector< int > IndicesSetting(DRC_CONSTRAINT_T aConstraint) const
Every rule that sets aConstraint, whichever page edits it.
void SetText(const wxString &aText)
Take the text of the Custom Rules page.
bool Save(wxString *aError)
Write the board's rules file.
static size_t FindConstraintClause(const wxString &aText, const wxString &aCode)
Position of the constraint clause for aCode in rule text, or npos.
void UpdateEntry(int aIndex, const DRC_RE_LOADED_PANEL_ENTRY &aEdited)
Write an edited rule back.
std::vector< DRC_RE_LOADED_PANEL_ENTRY > & Entries()
std::vector< int > IndicesFor(DRC_RULE_EDITOR_CONSTRAINT_NAME aType) const
void Load()
Read the board's own rules file.
static std::set< DRC_CONSTRAINT_T > ConstraintsOf(const DRC_RE_LOADED_PANEL_ENTRY &aEntry)
The DRC constraints a rule sets, read back through the rules parser.
bool parseInto(const wxString &aText)
wxString UniqueRuleName(const wxString &aBase) const
void Remove(int aIndex)
std::vector< DRC_RE_LOADED_PANEL_ENTRY > m_entries
int Add(const DRC_RE_LOADED_PANEL_ENTRY &aEntry)
DRC_RULE_DOCUMENT(BOARD *aBoard)
void LoadFrom(const wxString &aPath)
Replace the rules with those of another board's file, as an import.
bool IsRuleNameUnique(const wxString &aName, DRC_RULE_EDITOR_CONSTRAINT_NAME aType, int aExceptIndex) const
DRC_RE_FILE_TRIVIA m_trivia
bool load(const wxString &aPath)
Returns false when the file could not be read, leaving the document as it was.
wxString GetText() const
The rules as text, for the Custom Rules page.
int Duplicate(int aIndex)
bool Move(int aIndex, int aDelta, DRC_RULE_EDITOR_CONSTRAINT_NAME aType)
Move a rule one step among the rules listed for aType.
DRC_RULE_EDITOR_CONSTRAINT_NAME
The text of a rules file that lies outside every rule, kept so a save can reproduce it.
Represents a rule loaded from a .kicad_dru file and mapped to a panel.