KiCad PCB EDA Suite
Loading...
Searching...
No Matches
template_fieldnames.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 (C) 2010 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <initializer_list>
24
25#include <wx/string.h>
26
27class OUTPUTFORMATTER;
28class TEMPLATE_FIELDNAMES_LEXER;
29
30
54
55#define MANDATORY_FIELDS { FIELD_T::REFERENCE, \
56 FIELD_T::VALUE, \
57 FIELD_T::FOOTPRINT, \
58 FIELD_T::DATASHEET, \
59 FIELD_T::DESCRIPTION }
60
61#define GLOBALLABEL_MANDATORY_FIELDS { FIELD_T::INTERSHEET_REFS }
62
63#define SHEET_MANDATORY_FIELDS { FIELD_T::SHEET_NAME, \
64 FIELD_T::SHEET_FILENAME }
65
66// A helper to call GetDefaultFieldName with or without translation.
67// Translation should be used only to display field names in dialogs
68#define DO_TRANSLATE true
69
70
79wxString GetDefaultFieldName( FIELD_T aFieldId, bool aTranslateForHI );
80wxString GetUserFieldName( int aFieldNdx, bool aTranslateForHI );
81
82
83inline wxString GetCanonicalFieldName( FIELD_T aFieldType )
84{
85 return GetDefaultFieldName( aFieldType, !DO_TRANSLATE );
86}
87
88
102bool FieldNamesAreDuplicates( const wxString& aLhs, const wxString& aRhs,
103 std::initializer_list<FIELD_T> aMandatoryFields );
104
105
109bool FieldNamesAreDuplicates( const wxString& aLhs, const wxString& aRhs );
110
111
118{
120 m_Visible( false ),
121 m_URL( false )
122 {
123 }
124
125 TEMPLATE_FIELDNAME( const wxString& aName ) :
126 m_Name( aName ),
127 m_Visible( false ),
128 m_URL( false )
129 {
130 }
131
133 {
134 m_Name = ref.m_Name;
135 m_Visible = ref.m_Visible;
136 m_URL = ref.m_URL;
137 }
138
142 void Format( OUTPUTFORMATTER* out ) const ;
143
156 void Parse( TEMPLATE_FIELDNAMES_LEXER* aSpec );
157
158 wxString m_Name; // The field name
159 bool m_Visible; // Field defaults to being visible in schematic.
160 bool m_URL; // If field should have a browse button
161};
162
163
165{
166public:
168 m_resolvedDirty( true )
169 { }
170
174 void Format( OUTPUTFORMATTER* out, bool aGlobal ) const ;
175
186 void AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, bool aGlobal );
187
191 void AddTemplateFieldNames( const wxString& aSerializedFieldNames );
192
196 void DeleteAllFieldNameTemplates( bool aGlobal );
197
201 const std::vector<TEMPLATE_FIELDNAME>& GetTemplateFieldNames();
202
206 const std::vector<TEMPLATE_FIELDNAME>& GetTemplateFieldNames( bool aGlobal );
207
214 const TEMPLATE_FIELDNAME* GetFieldName( const wxString& aName );
215
216protected:
217 void resolveTemplates();
218
219 void parse( TEMPLATE_FIELDNAMES_LEXER* in, bool aGlobal );
220
221private:
222 std::vector<TEMPLATE_FIELDNAME> m_globals;
223 std::vector<TEMPLATE_FIELDNAME> m_project;
224
225 // Combined list. Project templates override global ones.
226 std::vector<TEMPLATE_FIELDNAME> m_resolved;
228};
An interface used to output 8 bit text in a convenient way.
Definition richio.h:291
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Insert or append a wanted symbol field name into the field names template.
void AddTemplateFieldNames(const wxString &aSerializedFieldNames)
Add a serialized list of template field names.
const std::vector< TEMPLATE_FIELDNAME > & GetTemplateFieldNames()
Return a template field name list for read only access.
std::vector< TEMPLATE_FIELDNAME > m_resolved
void resolveTemplates()
Flatten project and global templates into a single list.
std::vector< TEMPLATE_FIELDNAME > m_project
const TEMPLATE_FIELDNAME * GetFieldName(const wxString &aName)
Search for aName in the template field name list.
void DeleteAllFieldNameTemplates(bool aGlobal)
Delete the entire contents.
void parse(TEMPLATE_FIELDNAMES_LEXER *in, bool aGlobal)
std::vector< TEMPLATE_FIELDNAME > m_globals
void Format(OUTPUTFORMATTER *out, bool aGlobal) const
Serialize this object out as text into the given OUTPUTFORMATTER.
@ USER
The main config directory (e.g. ~/.config/kicad/)
Hold a name of a symbol's field, field value, and default visibility.
void Format(OUTPUTFORMATTER *out) const
Serialize this object out as text into the given OUTPUTFORMATTER.
void Parse(TEMPLATE_FIELDNAMES_LEXER *aSpec)
Fill this object from information in the input stream aSpec, which is a #TEMPLATE_FIELDNAMES_LEXER.
TEMPLATE_FIELDNAME(const wxString &aName)
TEMPLATE_FIELDNAME(const TEMPLATE_FIELDNAME &ref)
#define DO_TRANSLATE
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ INTERSHEET_REFS
Global label cross-reference page numbers.
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
bool FieldNamesAreDuplicates(const wxString &aLhs, const wxString &aRhs, std::initializer_list< FIELD_T > aMandatoryFields)
Test whether two field names should be treated as duplicates for the purposes of field name uniquenes...
wxString GetUserFieldName(int aFieldNdx, bool aTranslateForHI)
wxString GetCanonicalFieldName(FIELD_T aFieldType)
wxString GetDefaultFieldName(FIELD_T aFieldId, bool aTranslateForHI)
Return a default symbol field name for a mandatory field type.