41 const std::vector<DRC_RE_LOADED_PANEL_ENTRY>& aEntries,
44 wxFFile file( aPath,
"w" );
46 if( !file.IsOpened() )
50 file.Write( content );
60 wxString
result =
"(version 1)\n";
64 std::vector<std::pair<std::pair<wxString, wxString>, std::vector<const DRC_RE_LOADED_PANEL_ENTRY*>>>
66 std::map<std::pair<wxString, wxString>,
size_t> groupIndex;
70 auto key = std::make_pair( entry.ruleName, entry.condition );
71 auto it = groupIndex.find( key );
73 if( it == groupIndex.end() )
75 groupIndex[key] = groupedEntries.size();
76 groupedEntries.push_back( { key, { &entry } } );
80 groupedEntries[it->second].second.push_back( &entry );
85 for(
const auto& [key, entries] : groupedEntries )
89 if( entries.size() == 1 )
100 if( !ruleText.IsEmpty() )
101 result += ruleText +
"\n";
109 const BOARD* aBoard )
117 return wxEmptyString;
121 if( ruleText.IsEmpty() )
142 if( !severityClause.IsEmpty() && !ruleText.Contains(
"(severity" ) )
145 size_t lastParen = ruleText.rfind(
')' );
147 if( lastParen != wxString::npos )
149 ruleText = ruleText.Left( lastParen ) +
"\n\t" + severityClause +
")";
160 if( !aBoard || !aLayers.any() )
161 return wxEmptyString;
163 wxString layerStr =
"(layer";
166 layerStr +=
" \"" + aBoard->
GetLayerName( layer ) +
"\"";
182 default:
return wxEmptyString;
188 const std::vector<const DRC_RE_LOADED_PANEL_ENTRY*>& aEntries,
189 const BOARD* aBoard )
191 if( aEntries.empty() )
192 return wxEmptyString;
196 bool allUnedited =
true;
198 for(
const auto* entry : aEntries )
200 if( entry->wasEdited )
207 if( allUnedited && !aEntries[0]->originalRuleText.IsEmpty() )
208 return aEntries[0]->originalRuleText;
218 for(
const auto* entry : aEntries )
220 if( entry->layerCondition.any() && aBoard )
228 std::vector<wxString> allClauses;
230 for(
const auto* entry : aEntries )
232 if( entry->constraintData )
235 entryCtx.
ruleName = entry->ruleName;
237 entryCtx.
constraintCode = entry->constraintData->GetConstraintCode();
239 auto clauses = entry->constraintData->GetConstraintClauses( entryCtx );
241 for(
const wxString& clause : clauses )
243 if( !clause.IsEmpty() )
244 allClauses.push_back( clause );
255 rule << wxS(
"\t" ) << ctx.
layerClause << wxS(
"\n" );
257 for(
const wxString& clause : allClauses )
258 rule << wxS(
"\t" ) << clause << wxS(
"\n" );
262 rule << wxS(
"\t(condition \"" )
267 for(
const auto* entry : aEntries )
Information pertinent to a Pcbnew printed circuit board.
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
wxString GetConstraintCode() const
static wxString sanitizeRuleName(const wxString &aRuleName)
Sanitize a rule name for use in S-expression output.
virtual wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext)
wxString GetGeneratedRule() const
bool SaveFile(const wxString &aPath, const std::vector< DRC_RE_LOADED_PANEL_ENTRY > &aEntries, const BOARD *aBoard=nullptr)
Save all panel entries to a file.
wxString generateLayerClause(const LSET &aLayers, const BOARD *aBoard)
Generate a layer clause from an LSET.
wxString generateRuleText(const DRC_RE_LOADED_PANEL_ENTRY &aEntry, const BOARD *aBoard)
Generate the rule text for a single panel entry.
wxString GenerateRulesText(const std::vector< DRC_RE_LOADED_PANEL_ENTRY > &aEntries, const BOARD *aBoard=nullptr)
Generate rule text from panel entries.
wxString generateMergedRuleText(const std::vector< const DRC_RE_LOADED_PANEL_ENTRY * > &aEntries, const BOARD *aBoard)
Generate a merged rule text from multiple panel entries with the same name/condition.
wxString generateSeverityClause(SEVERITY aSeverity)
Generate a severity clause.
LSET is a set of PCB_LAYER_IDs.
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
wxString GetComment()
Get the comment associated with the rule.
PCB_LAYER_ID
A quick note on layer IDs:
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
Represents a rule loaded from a .kicad_dru file and mapped to a panel.
wxString originalRuleText
std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > constraintData
wxString conditionExpression
wxString result
Test unit parsing edge cases and error handling.