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 <kicommon.h>
26#include <wx/string.h>
27
28class OUTPUTFORMATTER;
29class TEMPLATE_FIELDNAMES_LEXER;
30
31
55
56#define MANDATORY_FIELDS { FIELD_T::REFERENCE, \
57 FIELD_T::VALUE, \
58 FIELD_T::FOOTPRINT, \
59 FIELD_T::DATASHEET, \
60 FIELD_T::DESCRIPTION }
61
62#define GLOBALLABEL_MANDATORY_FIELDS { FIELD_T::INTERSHEET_REFS }
63
64#define SHEET_MANDATORY_FIELDS { FIELD_T::SHEET_NAME, \
65 FIELD_T::SHEET_FILENAME }
66
67// Translation should be used only to display field names in dialogs
73
74
83KICOMMON_API wxString GetDefaultFieldName( FIELD_T aFieldId, TRANSLATION aTranslation );
84KICOMMON_API wxString GetUserFieldName( int aFieldNdx, TRANSLATION aTranslation );
85
86
101KICOMMON_API bool FieldNamesAreDuplicates( const wxString& aLhs, const wxString& aRhs,
102 std::initializer_list<FIELD_T> aMandatoryFields );
103
104
108KICOMMON_API bool FieldNamesAreDuplicates( const wxString& aLhs, const wxString& aRhs );
109
110
117{
119 m_Visible( false ),
120 m_URL( false )
121 {
122 }
123
124 TEMPLATE_FIELDNAME( const wxString& aName ) :
125 m_Name( aName ),
126 m_Visible( false ),
127 m_URL( false )
128 {
129 }
130
132 {
133 m_Name = ref.m_Name;
134 m_Visible = ref.m_Visible;
135 m_URL = ref.m_URL;
136 }
137
141 void Format( OUTPUTFORMATTER* out ) const ;
142
155 void Parse( TEMPLATE_FIELDNAMES_LEXER* aSpec );
156
157 wxString m_Name; // The field name
158 bool m_Visible; // Field defaults to being visible in schematic.
159 bool m_URL; // If field should have a browse button
160};
161
162
164{
165public:
166 enum class SCOPE
167 {
170 };
171
173 m_resolvedDirty( true )
174 { }
175
179 void Format( OUTPUTFORMATTER* out, SCOPE aScope ) const;
180
191 void AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName, SCOPE aScope );
192
196 void AddTemplateFieldNames( const wxString& aSerializedFieldNames, SCOPE aScope );
197
201 void DeleteFieldNameTemplates( SCOPE aScope );
202
206 const std::vector<TEMPLATE_FIELDNAME>& GetResolvedTemplateFieldNames();
207
211 const std::vector<TEMPLATE_FIELDNAME>& GetTemplateFieldNames( SCOPE aScope );
212
219 const TEMPLATE_FIELDNAME* GetFieldName( const wxString& aName );
220
221protected:
222 void resolveTemplates();
223
224 void parse( TEMPLATE_FIELDNAMES_LEXER* in, SCOPE aScope );
225
226private:
227 std::vector<TEMPLATE_FIELDNAME> m_globals;
228 std::vector<TEMPLATE_FIELDNAME> m_project;
229
230 // Combined list. Project templates override global ones.
231 std::vector<TEMPLATE_FIELDNAME> m_resolved;
233};
An interface used to output 8 bit text in a convenient way.
Definition richio.h:294
std::vector< TEMPLATE_FIELDNAME > m_resolved
std::vector< TEMPLATE_FIELDNAME > m_project
std::vector< TEMPLATE_FIELDNAME > m_globals
LIB_FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE SCOPE
@ USER
The main config directory (e.g. ~/.config/kicad/)
#define KICOMMON_API
Definition kicommon.h:27
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition ptree.cpp:194
Hold a name of a symbol's field, field value, and default visibility.
TEMPLATE_FIELDNAME(const wxString &aName)
TEMPLATE_FIELDNAME(const TEMPLATE_FIELDNAME &ref)
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
@ VALUE
Field Value of part, i.e. "3.3K".
@ UNTRANSLATED
@ TRANSLATED
KICOMMON_API wxString GetUserFieldName(int aFieldNdx, TRANSLATION aTranslation)
KICOMMON_API 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...
KICOMMON_API wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.