KiCad PCB EDA Suite
Loading...
Searching...
No Matches
DRC_RULE_DOCUMENT Class Reference

The custom rules of one board, held in memory while Board Setup is open. More...

#include <drc_rule_document.h>

Public Member Functions

 DRC_RULE_DOCUMENT (BOARD *aBoard)
 
void Load ()
 Read the board's own rules file.
 
void LoadFrom (const wxString &aPath)
 Replace the rules with those of another board's file, as an import.
 
bool Save (wxString *aError)
 Write the board's rules file.
 
wxString GetText () const
 The rules as text, for the Custom Rules page.
 
void SetText (const wxString &aText)
 Take the text of the Custom Rules page.
 
std::vector< DRC_RE_LOADED_PANEL_ENTRY > & Entries ()
 
std::vector< int > IndicesFor (DRC_RULE_EDITOR_CONSTRAINT_NAME aType) const
 
std::vector< int > IndicesSetting (DRC_CONSTRAINT_T aConstraint) const
 Every rule that sets aConstraint, whichever page edits it.
 
int Add (const DRC_RE_LOADED_PANEL_ENTRY &aEntry)
 
void UpdateEntry (int aIndex, const DRC_RE_LOADED_PANEL_ENTRY &aEdited)
 Write an edited rule back.
 
void Remove (int aIndex)
 
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.
 
bool IsRuleNameUnique (const wxString &aName, DRC_RULE_EDITOR_CONSTRAINT_NAME aType, int aExceptIndex) const
 
wxString UniqueRuleName (const wxString &aBase) const
 
int NextId ()
 
bool IsModified () const
 
bool HasUnparsedText () const
 True while the Custom Rules text could not be parsed.
 

Static Public Member Functions

static size_t FindConstraintClause (const wxString &aText, const wxString &aCode)
 Position of the constraint clause for aCode in rule text, or npos.
 
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.
 

Private Member Functions

bool load (const wxString &aPath)
 Returns false when the file could not be read, leaving the document as it was.
 
bool parseInto (const wxString &aText)
 
void prepareEntries ()
 
void touch ()
 

Private Attributes

BOARD * m_board
 
std::vector< DRC_RE_LOADED_PANEL_ENTRY > m_entries
 
DRC_RE_FILE_TRIVIA m_trivia
 
wxString m_rawText
 
bool m_hasRawText
 
bool m_textCurrent
 
bool m_modified
 
int m_nextId
 
int m_nextGroupId
 

Detailed Description

The custom rules of one board, held in memory while Board Setup is open.

Every Design Rules page edits this one object. The rules file is written once, when the dialog is accepted, and never touched before that.

Definition at line 41 of file drc_rule_document.h.

Constructor & Destructor Documentation

◆ DRC_RULE_DOCUMENT()

DRC_RULE_DOCUMENT::DRC_RULE_DOCUMENT ( BOARD * aBoard)

Definition at line 38 of file drc_rule_document.cpp.

References m_board, m_hasRawText, m_modified, m_nextGroupId, m_nextId, and m_textCurrent.

Member Function Documentation

◆ Add()

◆ ConstraintsOf()

◆ Duplicate()

int DRC_RULE_DOCUMENT::Duplicate ( int aIndex)

◆ Entries()

◆ FindConstraintClause()

size_t DRC_RULE_DOCUMENT::FindConstraintClause ( const wxString & aText,
const wxString & aCode )
static

Position of the constraint clause for aCode in rule text, or npos.

The code must end at a delimiter so a code that starts like another is not matched.

Definition at line 497 of file drc_rule_document.cpp.

References end, and isSpace().

Referenced by BOOST_AUTO_TEST_CASE(), and CONSTRAINT_RULES_LIST::ConstraintText().

◆ GetText()

◆ HasUnparsedText()

bool DRC_RULE_DOCUMENT::HasUnparsedText ( ) const
inline

True while the Custom Rules text could not be parsed.

The pages must not edit entries then, because the text is what gets written.

Definition at line 111 of file drc_rule_document.h.

References m_hasRawText.

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ IndicesFor()

◆ IndicesSetting()

std::vector< int > DRC_RULE_DOCUMENT::IndicesSetting ( DRC_CONSTRAINT_T aConstraint) const

Every rule that sets aConstraint, whichever page edits it.

Definition at line 260 of file drc_rule_document.cpp.

References ConstraintsOf(), m_entries, m_hasRawText, and result.

◆ IsModified()

bool DRC_RULE_DOCUMENT::IsModified ( ) const
inline

◆ IsRuleNameUnique()

bool DRC_RULE_DOCUMENT::IsRuleNameUnique ( const wxString & aName,
DRC_RULE_EDITOR_CONSTRAINT_NAME aType,
int aExceptIndex ) const

Definition at line 448 of file drc_rule_document.cpp.

References m_entries.

Referenced by BOOST_AUTO_TEST_CASE().

◆ Load()

void DRC_RULE_DOCUMENT::Load ( )

Read the board's own rules file.

Nothing is marked modified.

Definition at line 49 of file drc_rule_document.cpp.

References load(), m_board, and m_modified.

◆ load()

bool DRC_RULE_DOCUMENT::load ( const wxString & aPath)
private

Returns false when the file could not be read, leaving the document as it was.

Definition at line 66 of file drc_rule_document.cpp.

References ConvertSmartQuotesAndDashes(), m_entries, m_hasRawText, m_rawText, m_textCurrent, m_trivia, parseInto(), and text.

Referenced by Load(), and LoadFrom().

◆ LoadFrom()

void DRC_RULE_DOCUMENT::LoadFrom ( const wxString & aPath)

Replace the rules with those of another board's file, as an import.

A board without a rules file changes nothing.

Definition at line 56 of file drc_rule_document.cpp.

References load(), and m_modified.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ Move()

bool DRC_RULE_DOCUMENT::Move ( int aIndex,
int aDelta,
DRC_RULE_EDITOR_CONSTRAINT_NAME aType )

Move a rule one step among the rules listed for aType.

Returns false when it is already first or last.

Definition at line 392 of file drc_rule_document.cpp.

References group, IndicesFor(), m_entries, m_hasRawText, and touch().

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ NextId()

int DRC_RULE_DOCUMENT::NextId ( )
inline

◆ parseInto()

bool DRC_RULE_DOCUMENT::parseInto ( const wxString & aText)
private

◆ prepareEntries()

void DRC_RULE_DOCUMENT::prepareEntries ( )
private

Definition at line 119 of file drc_rule_document.cpp.

References m_board, m_entries, m_nextGroupId, m_nextId, and LSET::Name().

Referenced by parseInto().

◆ Remove()

void DRC_RULE_DOCUMENT::Remove ( int aIndex)

Definition at line 337 of file drc_rule_document.cpp.

References m_entries, m_hasRawText, and touch().

Referenced by BOOST_AUTO_TEST_CASE().

◆ Save()

bool DRC_RULE_DOCUMENT::Save ( wxString * aError)

Write the board's rules file.

Returns false and fills aError when the write fails.

Definition at line 151 of file drc_rule_document.cpp.

References KIPLATFORM::IO::AtomicWriteFile(), GetText(), m_board, m_modified, text, and utf8().

◆ SetText()

◆ touch()

void DRC_RULE_DOCUMENT::touch ( )
private

Definition at line 490 of file drc_rule_document.cpp.

References m_modified, and m_textCurrent.

Referenced by Add(), Duplicate(), Move(), Remove(), and UpdateEntry().

◆ UniqueRuleName()

wxString DRC_RULE_DOCUMENT::UniqueRuleName ( const wxString & aBase) const

Definition at line 467 of file drc_rule_document.cpp.

References m_entries, and name.

Referenced by BOOST_AUTO_TEST_CASE(), and Duplicate().

◆ UpdateEntry()

Member Data Documentation

◆ m_board

BOARD* DRC_RULE_DOCUMENT::m_board
private

Definition at line 132 of file drc_rule_document.h.

Referenced by DRC_RULE_DOCUMENT(), GetText(), Load(), prepareEntries(), and Save().

◆ m_entries

◆ m_hasRawText

bool DRC_RULE_DOCUMENT::m_hasRawText
private

◆ m_modified

bool DRC_RULE_DOCUMENT::m_modified
private

Definition at line 138 of file drc_rule_document.h.

Referenced by DRC_RULE_DOCUMENT(), IsModified(), Load(), LoadFrom(), Save(), SetText(), and touch().

◆ m_nextGroupId

int DRC_RULE_DOCUMENT::m_nextGroupId
private

Definition at line 140 of file drc_rule_document.h.

Referenced by Add(), DRC_RULE_DOCUMENT(), Duplicate(), and prepareEntries().

◆ m_nextId

int DRC_RULE_DOCUMENT::m_nextId
private

Definition at line 139 of file drc_rule_document.h.

Referenced by DRC_RULE_DOCUMENT(), NextId(), and prepareEntries().

◆ m_rawText

wxString DRC_RULE_DOCUMENT::m_rawText
private

Definition at line 135 of file drc_rule_document.h.

Referenced by GetText(), load(), and SetText().

◆ m_textCurrent

bool DRC_RULE_DOCUMENT::m_textCurrent
private

Definition at line 137 of file drc_rule_document.h.

Referenced by DRC_RULE_DOCUMENT(), GetText(), load(), SetText(), and touch().

◆ m_trivia

DRC_RE_FILE_TRIVIA DRC_RULE_DOCUMENT::m_trivia
private

Definition at line 134 of file drc_rule_document.h.

Referenced by GetText(), load(), and parseInto().


The documentation for this class was generated from the following files: